久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

SpringBoot實現發送郵件功能過程圖解

瀏覽:90日期:2023-05-29 08:05:55

首先創建一個郵箱賬號,建議@126.com,@163.com,@qq.com 都可以

開啟smtp,以下是使用圖解:

SpringBoot實現發送郵件功能過程圖解

SpringBoot實現發送郵件功能過程圖解

創建SpringBoot項目導入依賴

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 支持發送郵件 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>

application.properties文件中配置:

spring.mail.default-encoding=UTF-8spring.mail.host=smtp.163.com#發送者的郵箱密碼spring.mail.password=xxxxx#端口spring.mail.port=25#協議spring.mail.protocol=smtp#發送者的郵箱賬號spring.mail.username=xxxxxxx@163.comserver.port=8081

 以文本的形式發送:

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 */@RestControllerpublic class MailController { @Autowired JavaMailSender jsm; @Value('${spring.mail.username}') private String username; @GetMapping('/send') public String send(){ //建立郵箱消息 SimpleMailMessage message = new SimpleMailMessage(); //發送者 message.setFrom(username); //接收者 message.setTo('1352192872@qq.com'); //發送標題 message.setSubject('測試'); //發送內容 message.setText('測試數據'); jsm.send(message); return '1'; }}

 結果:

發送方:

SpringBoot實現發送郵件功能過程圖解

接收方:

SpringBoot實現發送郵件功能過程圖解

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 荥阳市| 洱源县| 萝北县| 鹤峰县| 普兰店市| 东丰县| 柘城县| 郑州市| 磴口县| 沙雅县| 桂林市| 鹿邑县| 曲松县| 阿坝县| 来宾市| 宁津县| 伽师县| 遂平县| 兰州市| 冀州市| 巴塘县| 偏关县| 石台县| 蕉岭县| 行唐县| 长春市| 泗阳县| 平江县| 苍溪县| 克拉玛依市| 桃源县| 旌德县| 林甸县| 航空| 大港区| 囊谦县| 美姑县| 蕲春县| 天镇县| 崇阳县| 依兰县|