When we receive a MimeMessage
which contains recipient InternetAddresses
containing square brackets, we get 'javax.mail.internet.AddressException: Local address contains illegal character in string
' when we call MimeMessage.getAllRecipients()
.
The email address below is one example where we get the above exception:
"ABC NAME-DEM-SAST1" <ABCNAME-DEM-SAST1[[email protected]]>
Is the above example address an actual valid email address? And if it is, why can't an InternetAddress be created from it?
e.g. InternetAddress add = new InternetAddress("\"ABC NAME-DEM-SAST1\" <ABCNAME-DEM-SAST1[[email protected]]>"
, false);
I had a look at Javamail problem with ñ characters in mail addresses question for an answer but to no avail.
I am using javamail 1.4 and JVM is running on a Linux host system.
Any insight on this issue would be much appreciated!
Regards, PM.
This explanation indicates that "[" and "]" are invalid characters in an email address, except if used to bound a domain literal (e.g. [192.1.0.0]). If the example address should show a name and the corresponding address, a correct syntax would be
"ABC NAME-DEM-SAST1" <[email protected]>
Square brackets are used by Microsoft Office to mark one-off addresses ( http://msdn.microsoft.com/en-us/library/cc842281.aspx ), but that seems to be non-standardized and also does not match the given example.