欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

然后會(huì)提供個(gè)授權(quán)碼,用來發(fā)送郵件。忘記了,可以點(diǎn)生成授權(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號(hào)碼@qq.com
spring.mail.password=qq郵箱開啟SMTP提供的授權(quán)碼(注意:不是你的qq郵箱密碼)#下面一般不用動(dòng)
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、測(cè)試發(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測(cè)試郵件");
            smm.setText("簡(jiǎn)單文本郵件測(cè)試發(fā)送!");
            mailSender.send(smm);

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

相關(guān)文章

最新評(píng)論