This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Sending Email Exception: Illegal whitespace in address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending Email Exception: Illegal whitespace in address" Watch "Sending Email Exception: Illegal whitespace in address" New topic
Author

Sending Email Exception: Illegal whitespace in address

Siphiwe Madi
Ranch Hand

Joined: Aug 16, 2007
Posts: 70
Hi Guyz,

I'm having problems when trying to send an email through JavaMail API. an AddressException is thrown saying:

Illegal whitespace in address

My code looks like this:



Any assistance would be great.


Regards, Siphiwe Madi
[SCJP, SCWCD, __] Next ... scjwsd
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41053
    
  43
Seeing the exact address -character for character- that causes this issue sure would help.


Ping & DNS - my free Android networking tools app
Siphiwe Madi
Ranch Hand

Joined: Aug 16, 2007
Posts: 70
The address is passed as a String array as below:



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you sure it's the "to" address causing the problem?

It's easier if you are more precise with the problem from the beginning--otherwise we have to duplicate work you may have already done. Please see Tell The Details--if you get an exception, tell us when where it's happening. Show all the relevant data, like the "from" and "to" addresses. Give us as much information as seems reasonable--don't make us work more than we have to; we're lazy ;)
Siphiwe Madi
Ranch Hand

Joined: Aug 16, 2007
Posts: 70
I do think it is the "to" address because basically i'm sending the same address for the from and to, the other test data i'm passing from my Main method are as follows (main method snippet)



main method is calling this method

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Although Ulf had requested for the full email addresses, this made them available for spammers who search the 'Net for email addresses. I've changed them slightly to make it at least a bit more difficult.

Now, where does the exception occur? At setting the form address at or at the to addresses at If it is the latter, you can find out exactly which one it is by using a simple print statement:
The last printed email address will be the one causing the problems.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

A simple print statement, yes; but watch out for leading and trailing blanks which you might not notice if you used an excessively simple print statement.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Correct. Maybe System.out.println("|" + new InternetAddress(recip) + "|") is a better idea - the vertical bars then quickly show where the string actually starts and where it ends.

Come to think of it, that should be System.out.println("|" + recip + "|"). The InternetAddress constructor is throwing the exception, so you would just move the exception one statement up...
Siphiwe Madi
Ranch Hand

Joined: Aug 16, 2007
Posts: 70
Rob Prime wrote:Although Ulf had requested for the full email addresses, this made them available for spammers who search the 'Net for email addresses. I've changed them slightly to make it at least a bit more difficult.

Now, where does the exception occur? At setting the form address at or at the to addresses at If it is the latter, you can find out exactly which one it is by using a simple print statement:
The last printed email address will be the one causing the problems.


Hi,

The error was occuring on at the to addresses. This is working now

I think passing the strict boolean value as false to the constructor (as below) has sorted this.


Thanks for the assistance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending Email Exception: Illegal whitespace in address
 
Similar Threads
java mail smtp host prob.
java mail throws
Can't send mail with gwt
java mail smtp host prob.
Having Problem in sending mail