異常一:
javax.mail.MessagingException: Could not convert socket to TLS
原因:
嘗試訪問(wèn)不受信任地址默勾。
解決:
把當(dāng)前smtp host設(shè)為可信任,在配置文件application.properties中增加如下配置:
spring.mail.properties.mail.smtp.ssl.trust=cloud.submail.cn
完整的smtp郵件配置如下:
spring.mail.host=cloud.submail.cn
spring.mail.port=587
spring.mail.username=在SUBMAIL中創(chuàng)建的APPID
spring.mail.password=在SUBMAIL中創(chuàng)建的APPKEY
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.ssl.trust=cloud.submail.cn
異常二:
217 Invalid domain, Domain record does not exist
原因:
在SUBMAIL配置的域名和在使用SMTP發(fā)送郵件時(shí)使用的發(fā)件人域名不匹配造成的,如:在SUBMAIL配置a.com域名鲸阔,SMTP請(qǐng)求的發(fā)件人卻是xxx@b.com,應(yīng)該為xxx@a.com颓帝。
解決:
將helper.setFrom("xxx@b.com")修改為helper.setFrom("xxx@a.com")