SpringBoot 整合Mail发送功能问题与解决

SpringBootLean 是对springboot学习与研究项目,是根据实际项目的形式对进行配置与处理,欢迎star与fork。
[oschina 地址]
http://git.oschina.net/cmlbeliever/SpringBootLearning
[github 地址]
https://github.com/cmlbeliever/SpringBootLearning

在项目中,发送邮件功能还是非常常见的,最近将邮件功能整合到springboot中,代码已经提交到branch-mail分支上,具体事项请查看README.MD上的说明。

这里记录下整合邮件功能遇到的问题与解决办法。

第一步 导入引入相关jar

    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

第二步 在config/application.properties上配置相关信息,这里demo用的是163邮箱

spring.mail.from=**@163.com
spring.mail.host=smtp.163.com
spring.mail.password=邮箱安全密码
spring.mail.properties.smtp.auth=true
spring.mail.properties.smtp.timeout=25000
spring.mail.username=**@163.com

配置完以上信息后就可以直接执行单元测试的了

com.cml.springboot.controller.test.MailSenderTest

具体功能请检出工程后自行测试。

问题1 发送邮件535错误

org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535 Error: authentication failed

问题1解决

问题是因为配置文件中配置的邮箱密码是登录密码而不是安全密码导致的,直接将密码修改成安全密码就可以了(163邮箱在开启smtp服务时会要求输入安全密码的)

问题2

554 DT:SPM 163 smtp10,DsCowACXs5lqAXJYldK2GQ–.5581S2 1483866477,please see http://mail.163.com/help/help_spam_16.htm?ip=220.179.147.26&hostid=smtp10&time=1483866477

问题2解决

引发次问题是因为此邮件触发了163邮箱服务器反垃圾规则,测试邮件发送的内容是:”你好!试试”,这样也能出发反垃圾规则,感觉莫名其妙,把内容改为”1111111”,邮件正常发送。所以发送邮件的时候需要具体查看下163邮件的规则。具体原因在错误上已经提示了,到网址:http://mail.163.com/help/help_spam_16.htm?ip=220.179.147.26&hostid=smtp10&time=1483866477上查看即可

posted @ 2017-01-08 17:45  小小架构师  阅读(1193)  评论(0编辑  收藏  举报