问题描述
我在创建通过org.springframework.mail.javamail.MimeMessageHelper
发送的电子邮件地址时遇到了麻烦:
final InternetAddress from = new InternetAddress("foo@example.com", "Two words");
并且收到的消息中的结果是“ From
,其格式为:
"Two words <foo@example.com>" <foo@example.com>
但是我想要的是:
"Two words" <foo@example.com>
问:我的代码有什么问题?
1楼
使用javax.mail的1.5.0-b1版本,以下程序
import java.io.UnsupportedEncodingException;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class Email {
public Email() {
}
public static void main(String[] args) throws UnsupportedEncodingException, AddressException {
final InternetAddress from = new InternetAddress("foo@example.com", "Two words");
System.out.println(from);
final InternetAddress from2 = new InternetAddress("\"Two words\" <foo@example.com>");
System.out.println(from2);
}
}
输出
Two words <foo@example.com>
Two words <foo@example.com>
...