SpringBoot+JavaMailSender實(shí)現(xiàn)騰訊企業(yè)郵箱配置
1. 引入spring-boot-starter-mail 依賴包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId></dependency>
2. 在application.yml配置郵箱基本信息
spring: mail: host: smtp.exmail.qq.com port: 465 username: xxx@xx.com password: xxxx protocol: smtp properties: mail:smtp: auth: true ssl: enable: true socketFactory: class: com.sun.mail.util.MailSSLSocketFactory fallback: false
3. 實(shí)現(xiàn)代碼
@Autowired JavaMailSender javaMailSender; public void testSend() { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom('XXX@xxx.com'); //發(fā)送者郵箱地址 此地址一定要和yml郵箱一致 message.setTo('xxx@xxx.com'); //收件人郵箱地址 message.setSubject('測試主題'); message.setText('測試內(nèi)容'); jms.send(message); }
注意:
如果代碼報(bào):501 mail from address must be same as authorization user 錯誤 ;引起原因是yml中配置的郵箱地址和代碼中message.setFrom(xx@xx.com);不一致導(dǎo)致;
到此這篇關(guān)于SpringBoot+JavaMailSender實(shí)現(xiàn)騰訊企業(yè)郵箱配置的文章就介紹到這了,更多相關(guān)SpringBoot JavaMailSender騰訊郵箱配置內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
