File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 42919
    
  68
Seeing the exact address -character for character- that causes this issue sure would help.
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: 19784
    
  20

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: 18987
    
    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: 19784
    
  20

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