SpringBoot+JavaMailSender實現騰訊企業郵箱配置
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: [email protected] password: xxxx protocol: smtp properties: mail:smtp: auth: true ssl: enable: true socketFactory: class: com.sun.mail.util.MailSSLSocketFactory fallback: false
3. 實現代碼
@Autowired JavaMailSender javaMailSender; public void testSend() { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom('[email protected]'); //發送者郵箱地址 此地址一定要和yml郵箱一致 message.setTo('[email protected]'); //收件人郵箱地址 message.setSubject('測試主題'); message.setText('測試內容'); jms.send(message); }
注意:
如果代碼報:501 mail from address must be same as authorization user 錯誤 ;引起原因是yml中配置的郵箱地址和代碼中message.setFrom([email protected]);不一致導致;
到此這篇關于SpringBoot+JavaMailSender實現騰訊企業郵箱配置的文章就介紹到這了,更多相關SpringBoot JavaMailSender騰訊郵箱配置內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章: