SpringBoot實(shí)現(xiàn)發(fā)送郵件功能過(guò)程圖解
首先創(chuàng)建一個(gè)郵箱賬號(hào),建議@126.com,@163.com,@qq.com 都可以
開(kāi)啟smtp,以下是使用圖解:


創(chuàng)建SpringBoot項(xiàng)目導(dǎo)入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 支持發(fā)送郵件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
application.properties文件中配置:
spring.mail.default-encoding=UTF-8
spring.mail.host=smtp.163.com
#發(fā)送者的郵箱密碼
spring.mail.password=xxxxx
#端口
spring.mail.port=25
#協(xié)議
spring.mail.protocol=smtp
#發(fā)送者的郵箱賬號(hào)
spring.mail.username=xxxxxxx@163.com
server.port=8081
以文本的形式發(fā)送:
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author
* @site
* @company
* @create 2020-03-07 1:06
*/
@RestController
public class MailController {
@Autowired
JavaMailSender jsm;
@Value("${spring.mail.username}")
private String username;
@GetMapping("/send")
public String send(){
//建立郵箱消息
SimpleMailMessage message = new SimpleMailMessage();
//發(fā)送者
message.setFrom(username);
//接收者
message.setTo("1352192872@qq.com");
//發(fā)送標(biāo)題
message.setSubject("測(cè)試");
//發(fā)送內(nèi)容
message.setText("測(cè)試數(shù)據(jù)");
jsm.send(message);
return "1";
}
}
結(jié)果:
發(fā)送方:

接收方:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- springboot 使用QQ郵箱發(fā)送郵件的操作方法
- springboot發(fā)送郵件功能的實(shí)現(xiàn)代碼
- Springboot實(shí)現(xiàn)發(fā)送郵件及注冊(cè)激活步驟
- SpringBoot整合JavaMail通過(guò)阿里云企業(yè)郵箱發(fā)送郵件的實(shí)現(xiàn)
- 基于SpringBoot實(shí)現(xiàn)定時(shí)發(fā)送郵件過(guò)程解析
- SpringBoot實(shí)現(xiàn)發(fā)送郵件任務(wù)
- SpringBoot實(shí)現(xiàn)發(fā)送郵件功能
- SpringBoot使用FreeMarker模板發(fā)送郵件
- SpringBoot JavaMailSender發(fā)送郵件功能
- Springboot實(shí)現(xiàn)發(fā)送郵件
相關(guān)文章
Spring boot項(xiàng)目中異常攔截設(shè)計(jì)和處理詳解
這篇文章主要介給大家紹了關(guān)于Spring boot項(xiàng)目中異常攔截設(shè)計(jì)和處理的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用spring boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起看看吧2018-12-12
JDBC使用Statement修改數(shù)據(jù)庫(kù)
這篇文章主要為大家詳細(xì)介紹了JDBC使用Statement修改數(shù)據(jù)庫(kù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
簡(jiǎn)單了解Java方法的定義和使用實(shí)現(xiàn)詳解
這篇文章主要介紹了簡(jiǎn)單了解Java方法的定義和使用實(shí)現(xiàn)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12
javaweb Servlet開(kāi)發(fā)總結(jié)(二)
這篇文章主要為大家詳細(xì)介紹了javaweb Servlet開(kāi)發(fā)總結(jié)的第二篇,感興趣的小伙伴們可以參考一下2016-05-05
spring如何快速穩(wěn)定解決循環(huán)依賴問(wèn)題
這篇文章主要介紹了spring如何快速穩(wěn)定解決循環(huán)依賴問(wèn)題,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(24)
下面小編就為大家?guī)?lái)一篇Java基礎(chǔ)的幾道練習(xí)題(分享)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望可以幫到你2021-07-07
SpringBoot使用Jasypt對(duì)YML文件配置內(nèi)容加密的方法(數(shù)據(jù)庫(kù)密碼加密)
本文介紹了如何在SpringBoot項(xiàng)目中使用Jasypt對(duì)application.yml文件中的敏感信息(如數(shù)據(jù)庫(kù)密碼)進(jìn)行加密,通過(guò)引入Jasypt依賴、配置加密密鑰、加密敏感信息并測(cè)試解密功能,可以提高配置文件的安全性,減少因配置文件泄露導(dǎo)致的安全風(fēng)險(xiǎn),感興趣的朋友一起看看吧2025-03-03
IDEA配置Tomcat創(chuàng)建web項(xiàng)目的詳細(xì)步驟
Tomcat是一個(gè)Java?Web應(yīng)用服務(wù)器,實(shí)現(xiàn)了多個(gè)Java?EE規(guī)范(JSP、Java?Servlet等),這篇文章主要給大家介紹了關(guān)于IDEA配置Tomcat創(chuàng)建web項(xiàng)目的詳細(xì)步驟,需要的朋友可以參考下2023-12-12
SpringCloud hystrix服務(wù)降級(jí)學(xué)習(xí)筆記
什么是服務(wù)降級(jí)?當(dāng)服務(wù)器壓力劇增的情況下,根據(jù)實(shí)際業(yè)務(wù)情況及流量,對(duì)一些服務(wù)和頁(yè)面有策略的不處理或換種簡(jiǎn)單的方式處理,從而釋放服務(wù)器資源以保證核心交易正常運(yùn)作或高效運(yùn)作2022-10-10

