今天尝试用java.mail.jar来实现Java程序发送邮件的功能,遇到一些问题:
一、当使用QQ邮箱向网易邮箱发邮件时:
问题1:530错误,需要建立安全连接,报错如下:
javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28
解决:我在原来的初始化代码中加上SSL相关代码即可解决此错误,如下前四句代码:
private void init(String name, String pass, String smtpHostName) throws GeneralSecurityException{
//开启ssl加密,如果没有ssl加密,会报530错误
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
prop.put("mail.smtp.ssl.enable", "true");
prop.put("mail.smtp.ssl.socketFactory", sf);
prop.setProperty("mail.smtp.auth", "true");
prop.setProperty("mail.smtp.host", smtpHostName);
authticator =