I'm having problems with parse method when usising ñ
character:
essage.setRecipients(Message.RecipientType.TO, internetAddress.parse("somedir.withñchar@m ailserver.com",false));
I'm passing false for the strict parameter, but always i get the error:
javax.mail.internet.AddressException: Local address contains control or whitespace in string ``somedir.with±[email protected]''
at Mailer.main(Mailer.java:386)
Caused by: javax.mail.internet.AddressException: Local address contains control
or whitespace in string ``somedir.with±[email protected]''
at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java
:1155)
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1044)
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:575)
at Mailer.main(Mailer.java:377)
If you are still with this problem, I advise you to add double quotes to your unusual e-mail address like I did. It worked for me, because checkAddress method of InternetAddress give up to validate quoted address. That's the easy and quick solution.
Example:
unusual_email_without_at_sign_or_with_accentuátion (won't work)
"unusual_email_without_at_sign_or_with_accentuátion" (it works!)
The perfect and correct solution would be Java Team to fix InternetAddress class' bug that even receiving "strict=false" at constructor is checking the e-mail syntax, when it shouldn't.
Example of the bug:
InternetAddress i = new InternetAddress("unusual_email_without_at_sign_or_with_accentuátion ", false)
Example of the workaround solution:
InternetAddress i = new InternetAddress("\"unusual_email_without_at_sign_or_with_accentuátion\"", false)
The approach of creating a new class that extends Address won't work, since Transport.send() for some reason seems to validate again the address and the exception is also launched.
Please, let us know if it helped!
Verify that your ñ is actually an n-tilde. The following works perfectly for me
InternetAddress[] list = InternetAddress.parse("fred.joñ[email protected]", false);
for (InternetAddress a : list) {
System.out.println("[" + a + "]");
}
It also works when replacing the ñ with a unicode escape (in the source .java file)
InternetAddress[] list = InternetAddress.parse("fred.jo\[email protected]", false);
You could try replacing it like this just as a test.
Edit: BTW I had also used parse("...") with the address and no second parameter, and passed true
for strict, both of which also worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With