亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

spring boot發(fā)簡單文本郵件案例

 更新時間:2019年10月17日 10:10:22   作者:稚語希聽  
這篇文章主要介紹了spring boot發(fā)簡單文本郵件案例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

首先要去郵箱打開POP3/SMTP權(quán)限:

然后會提供個授權(quán)碼,用來發(fā)送郵件。忘記了,可以點生成授權(quán)碼再次生成。

1、引入spring boot自帶的mail依賴,這里版本用的:<spring-boot.version>1.4.3.RELEASE</spring-boot.version>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-mail</artifactId>
  <version>${spring-boot.version}</version>
  <scope>provided</scope>
</dependency>

2、spring boot配置文件添加郵箱參數(shù)信息

spring.mail.host=smtp.qq.com
spring.mail.username=你的qq號碼@qq.com
spring.mail.password=qq郵箱開啟SMTP提供的授權(quán)碼(注意:不是你的qq郵箱密碼)#下面一般不用動
spring.mail.default-encoding=${spring.http.encoding.charset}
spring.mail.properties.mail.smtp.connectiontimeout=5000 
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

3、測試發(fā)送

@Autowired
        private JavaMailSender mailSender;
        
        @Value("${spring.mail.username}")
        private String from;


SimpleMailMessage smm = new SimpleMailMessage();
            smm.setFrom(from);
            smm.setTo("發(fā)送方郵件地址");
            smm.setSubject("springboot測試郵件");
            smm.setText("簡單文本郵件測試發(fā)送!");
            mailSender.send(smm);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論