0

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[001-SAST1@domain.com]>

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[001-SAST1@domain.com]>", 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.

Community
  • 1
  • 1
Going Bananas
  • 2,265
  • 3
  • 43
  • 83

1 Answers1

1

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" <001-SAST1@domain.com>

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.

The email address RFC.

Pyranja
  • 3,529
  • 22
  • 24
  • Thanks for that info Pyranja. The messages we receive with recipient addresses formatted in this style all come from Exchange servers/Outlook clients. In order to successfully handle these non-standard recipient address formats I set the Session's property 'mail.mime.address.strict' to false. All SMTP messages we handle come direct from mail servers and not clients so we are making the assumption that recipient addresses have already been checked by the source mail server! I don't know if this the best available solution but at least we can now handle these type of recipient addresses okay. – Going Bananas Sep 27 '12 at 14:43