Javamail问题与邮件地址中的characters字符 [英] Javamail problem with ñ characters in mail addresses

查看:192
本文介绍了Javamail问题与邮件地址中的characters字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用ñ字符时遇到问题:

I'm having problems with parse method when usising ñ character:

essage.setRecipients(Message.RecipientType.TO, internetAddress.parse("somedir.withñchar@m ailserver.com",false));

我为strict参数传递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±har@mailserver.com''
at Mailer.main(Mailer.java:386)
Caused by: javax.mail.internet.AddressException: Local address contains control
or whitespace in string ``somedir.with±har@mailserver.com''
        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)


推荐答案

如果您仍然遇到此问题,我建议您在您不寻常的电子邮件地址中添加双引号就像我做的那样。它对我有用,因为InternetAddress的checkAddress方法放弃验证引用的地址。这是简单快捷的解决方案。

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.

示例:

unusual_email_without_at_sign_or_with_accentuátion (won't work)
"unusual_email_without_at_sign_or_with_accentuátion" (it works!)

完美而正确的解决方案是Java团队修复 InternetAddress类错误,即使在构造函数中接收strict = false,也会检查电子邮件语法,什么时候不应该。

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.

错误示例:

InternetAddress i = new InternetAddress("unusual_email_without_at_sign_or_with_accentuátion ", false)

变通方法解决方案示例:

InternetAddress i = new InternetAddress("\"unusual_email_without_at_sign_or_with_accentuátion\"", false)

创建一个新类的方法nds地址不起作用,因为出于某种原因,Transport.send()似乎再次验证地址,同时也启动了异常。

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!

这篇关于Javamail问题与邮件地址中的characters字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆