最近需要發送郵件,就找到Hutool工具來,感覺比較方便,可是在看案例的時候,都按照案例來的,一直報錯。我用的是126郵箱來的。
Exception in thread "main" cn.hutool.extra.mail.MailException: AuthenticationFailedException: 535 Error: authentication failed
源碼是這樣的
MailAccount account = new MailAccount();
account.setHost("smtp.126.com");
account.setPort(25);
account.setAuth(true);
account.setFrom("mikemhm@126.com");
account.setUser("mikemhm");
//密碼(注意不是登錄密碼,是網易客戶端登錄授權碼)
account.setPass("12345**");
MailUtil.send(account,CollUtil.newArrayList("bicc499@163.com"), "測試", "郵件來自Hutool測試", false);
一開始我用的密碼都是登錄密碼,一直顯示驗證錯誤,后來改成了授權碼,終於發送成功了。
