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

SpringBoot JavaMailSender發(fā)送郵件功能

 更新時間:2019年04月18日 08:40:55   作者:羅羅諾亞-小魚  
這篇文章主要為大家詳細(xì)介紹了SpringBoot JavaMailSender發(fā)送郵件功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了SpringBoot JavaMailSender發(fā)送郵件的具體代碼,供大家參考,具體內(nèi)容如下

引入Maven依賴包

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

163郵箱

application.properties

#####163郵箱########
spring.mail.host=smtp.163.com
spring.mail.username=*****@163.com
#163郵箱密碼
spring.mail.password=!@#$%^&*
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

運(yùn)行類:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
public class My163MailTest {

 @Autowired
 private JavaMailSender javaMailSender;

 @Value("${spring.mail.username}")
 private String username;

 @Test
 public void testSendSimple() {
 SimpleMailMessage message = new SimpleMailMessage();
 message.setFrom(username);
 message.setTo("*******@qq.com");
 message.setSubject("標(biāo)題:測試標(biāo)題");
 message.setText("測試內(nèi)容部份");
 javaMailSender.send(message);
 }
}

QQ郵箱和163郵箱的區(qū)別是需要設(shè)置授權(quán)碼而不是密碼,具體操作參考: 地址

application.properties

######qq郵箱########
spring.mail.host=smtp.qq.com
spring.mail.username=******@qq.com
#QQ郵箱授權(quán)碼
spring.mail.password=xuojxtkdojvzbhjj
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

運(yùn)行類:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Application.class)
public class MyQQMailTest {

 @Autowired
 private JavaMailSender javaMailSender;

 @Value("${spring.mail.username}")
 private String username;

 @Test
 public void testSendSimple() {
 SimpleMailMessage message = new SimpleMailMessage();
 message.setFrom(username);
 message.setTo("******@qq.com");
 message.setSubject("標(biāo)題:測試標(biāo)題");
 message.setText("測試內(nèi)容部份");
 javaMailSender.send(message);
 }
}

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

相關(guān)文章

  • Java連接mysql數(shù)據(jù)庫代碼實(shí)例程序

    Java連接mysql數(shù)據(jù)庫代碼實(shí)例程序

    這篇文章主要介紹了java連接mysql數(shù)據(jù)庫代碼實(shí)例程序,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Hibernate對數(shù)據(jù)庫刪除、查找、更新操作實(shí)例代碼

    Hibernate對數(shù)據(jù)庫刪除、查找、更新操作實(shí)例代碼

    本篇文章主要介紹了Hibernate對數(shù)據(jù)庫刪除、查找、更新操作實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Spring?Boot整合Log4j2.xml的問題及解決方法

    Spring?Boot整合Log4j2.xml的問題及解決方法

    這篇文章主要介紹了Spring?Boot整合Log4j2.xml的問題,本文給大家分享解決方案,需要的朋友可以參考下
    2023-09-09
  • springboot集成flyway自動創(chuàng)表的詳細(xì)配置

    springboot集成flyway自動創(chuàng)表的詳細(xì)配置

    Flayway是一款數(shù)據(jù)庫版本控制管理工具,支持?jǐn)?shù)據(jù)庫版本自動升級,Migrations可以寫成sql腳本,也可以寫在java代碼里;本文通過實(shí)例代碼給大家介紹springboot集成flyway自動創(chuàng)表的詳細(xì)過程,感興趣的朋友一起看看吧
    2021-06-06
  • springboot 異步調(diào)用的實(shí)現(xiàn)方法

    springboot 異步調(diào)用的實(shí)現(xiàn)方法

    這篇文章主要介紹了springboot 異步調(diào)用的實(shí)現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • Spring組件開發(fā)模式支持SPEL表達(dá)式

    Spring組件開發(fā)模式支持SPEL表達(dá)式

    今天小編就為大家分享一篇關(guān)于Spring組件開發(fā)模式支持SPEL表達(dá)式,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • 淺談SpringBoot處理url中的參數(shù)的注解

    淺談SpringBoot處理url中的參數(shù)的注解

    下面小編就為大家分享一篇淺談SpringBoot處理url中的參數(shù)的注解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Java實(shí)現(xiàn)常見的排序算法的示例代碼

    Java實(shí)現(xiàn)常見的排序算法的示例代碼

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)常見的排序算法(選擇排序、插入排序、希爾排序等)的相關(guān)資料,文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-10-10
  • Maven插件構(gòu)建Docker鏡像的實(shí)現(xiàn)步驟

    Maven插件構(gòu)建Docker鏡像的實(shí)現(xiàn)步驟

    這篇文章主要介紹了Maven插件構(gòu)建Docker鏡像的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • common-upload上傳文件功能封裝類分享

    common-upload上傳文件功能封裝類分享

    本文介紹一個common-upload上傳封裝類,為了更方便的上傳文件,對common-upload進(jìn)行了一個簡單的封裝,大家參考使用吧
    2014-01-01

最新評論