Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending Email Exception: Illegal whitespace in address

 
Siphiwe Madi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing the exact address -character for character- that causes this issue sure would help.
 
Siphiwe Madi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The address is passed as a String array as below:



 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic