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)入依賴(lài)
<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)文章
如何使用Java調(diào)用Linux系統(tǒng)命令
這篇文章主要介紹了如何使用Java調(diào)用Linux系統(tǒng)命令,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11
Spring中如何使用@Value注解實(shí)現(xiàn)給Bean屬性賦值
這篇文章主要介紹了Spring中如何使用@Value注解實(shí)現(xiàn)給Bean屬性賦值的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08
Java實(shí)現(xiàn)淘寶秒殺聚劃算搶購(gòu)自動(dòng)提醒源碼
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)淘寶秒殺聚劃算搶購(gòu)自動(dòng)提醒源碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
JAVA CountDownLatch與thread-join()的區(qū)別解析
這篇文章主要介紹了JAVA CountDownLatch與thread-join()的區(qū)別解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
idea查看properties中文變成unicode碼的解決方案
這篇文章主要介紹了idea查看properties中文變成unicode碼的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
詳解Spring Kafka中關(guān)于Kafka的配置參數(shù)
這篇文章主要介紹了詳解Spring Kafka中關(guān)于Kafka的配置參數(shù),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
如何從eureka獲取服務(wù)的ip和端口號(hào)進(jìn)行Http的調(diào)用
這篇文章主要介紹了如何從eureka獲取服務(wù)的ip和端口號(hào)進(jìn)行Http的調(diào)用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
java swing實(shí)現(xiàn)電影購(gòu)票系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了java swing實(shí)現(xiàn)電影購(gòu)票系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01
java8 stream自定義分組求和并排序的實(shí)現(xiàn)
這篇文章主要介紹了java8 stream自定義分組求和并排序的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01

