java邮件发送测试

使用了封装的MailUtils工具,做发送邮件测试:

 1 /*
 2  * 测试mailUtils
 3  * 底层依赖的是javamail:activation.jar,mail.jar  4 */  5 public class MailUtilsTest {  6  @Test  7 public void send() throws MessagingException, IOException{  8 Session createSession = MailUtils.createSession("smtp.163.com", "[email protected]", "13866817259yt");  9 Mail mail = new Mail("[email protected]", "[email protected]", "测试邮件一封", "<a href='http://www.baidu.com'>百度</a>"); 10  MailUtils.send(createSession, mail); 11  } 12 }

出现以下错误

1 javax.mail.AuthenticationFailedException: failed to connect

错误原因:

需要开启邮箱客户端授权密码,他是登录第三方邮件客户端的专用密码。

适用于登录以下服务: POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务.

猜你喜欢

转载自www.cnblogs.com/52haiyan/p/9540271.html