最后的解决方案是:去邮箱换个stmp链接凭证(密码),重新激活一下。
一、问题场景
今天去调试之前写过的邮件注册功能,搞着搞着就发现邮件发不了了,一看报错535。
我没有改动程序,所以不是程序的问题。就想看看问题是不是出在stmp服务器那边。
二、尝试解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
package test; import java.security.GeneralSecurityException; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.NoSuchProviderException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import com.sun.mail.util.MailSSLSocketFactory; public class registermail { public static void sendmail() { Properties prop = new Properties(); prop.setProperty("mail.host", "smtp.qq.com"); prop.setProperty("mail.transport.protocol", "smtp"); prop.setProperty("mail.smtp.auth", "true"); MailSSLSocketFactory ssl; try { ssl = new MailSSLSocketFactory(); ssl.setTrustAllHosts(true); prop.put("mail.smtp.ssl.enable", "true"); prop.put("mail.smtp.ssl.socketFactory", ssl); } catch (GeneralSecurityException e1) { e1.printStackTrace(); } // 使用JavaMail发送邮件的5个步骤 // 1、创建session Session session = Session.getInstance(prop); // 开启Session的debug模式,这样就可以查看到程序发送Email的运行状态,因为要结合使用,我就取消了回显功能 // session.setDebug(true); // 2、通过session得到transport对象 Transport ts; try { ts = session.getTransport(); // 3、使用邮箱的用户名和密码连上邮件服务器,发送邮件时,发件人需要提交邮箱的用户名和密码给smtp服务器,用户名和密码都通过验证之后才能够正常发送邮件给收件人。 ts.connect("smtp.qq.com", "503822883@qq.com", "***************"); // 4、创建邮件 Message message; message = createSimpleMail(session); // 5、发送邮件 ts.sendMessage(message, message.getAllRecipients()); ts.close(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public static MimeMessage createSimpleMail(Session session) throws Exception { // http://localhost:8080/12.8login/sever?method=yanzhen®istername=asd123123&biaoshima=B2E85BF9632E54199B27E1FF5&createdate=2015-12-15%2019:57:23.000000 // 创建邮件对象 MimeMessage message = new MimeMessage(session); // 指明邮件的发件人 message.setFrom(new InternetAddress("503822883@qq.com")); // 指明邮件的收件人,现在发件人和收件人是一样的,那就是自己给自己发 message.setRecipient(Message.RecipientType.TO, new InternetAddress(mailman.getEmail())); // 邮件的标题 message.setSubject("请完成您的注册"); // 邮件的文本内容 String url; url = "http://localhost:8080/12.8login/sever?method=yanzhen®istername=" + mailman.getUsername() + "&biaoshima=" + mailman.getBiaoshi() + "&createdate=" + mailman.getCreatetime(); message.setContent("<a href='" + url + "'>点击完成注册</a>", "text/html;charset=UTF-8"); // 返回创建好的邮件对象 return message; } // // public static void main(String[] args) { // mailman.setEmail("503822883@qq.com"); // mailman.setUsername("a503822883"); // mailman.setBiaoshi("A7575A88BA9FF5C25D33E271D"); // mailman.setCreatetime("2015-12-16 11:45:28.000000"); // sendmail(); // } } |
程序是没毛病的,之前正确运行过。所以我判断是stmp服务器出问题了,所以赶紧上邮箱看一看。
首先看邮箱的stmp功能,显示开启,那么重新获取一下密码。
重启服务器,就恢复了邮件功能了。
三、问题原因
为什么会导致503?
- 有些邮箱的stmp服务器好像定时让账号过期,进行僵尸账号的清理,这个时候会导致535 error。
- 你发送邮件太频繁了,服务器认为是垃圾邮件/骚扰邮件,决定让你冷静反省一下,所以重新进行验证。
- 你的邮件确实可疑,带有不良信息(有什么敏感的关键字)。
四、总结
535 error = 重新验证你的stmp账号 + 找到原因加以改正。