国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

springboot實(shí)現(xiàn)發(fā)送郵件(QQ郵箱為例)

瀏覽:136日期:2022-06-17 10:43:57

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

1.引入依賴(lài)

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

2.找到qq郵箱,開(kāi)啟smtp服務(wù),這里生成你的密碼,復(fù)制第三步用

springboot實(shí)現(xiàn)發(fā)送郵件(QQ郵箱為例)

springboot實(shí)現(xiàn)發(fā)送郵件(QQ郵箱為例)

3.password里輸入你獲取到的密碼(重點(diǎn):這里一定不能錯(cuò))

spring.mail.username=1550213743@qq.comspring.mail.password=********spring.mail.host=smtp.qq.com#開(kāi)啟加密驗(yàn)證spring.mail.properties.mail.smtp.ssl.enable=true

4.EmailApplicationTests類(lèi)里進(jìn)行測(cè)試, contextLoads為簡(jiǎn)單的發(fā)送,僅限于文本。contextLoads2為復(fù)雜,可以發(fā)送圖片,html格式

package com.xyj;import org.junit.jupiter.api.Test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.mail.SimpleMailMessage;import org.springframework.mail.javamail.JavaMailSender;import org.springframework.mail.javamail.JavaMailSenderImpl;import org.springframework.mail.javamail.MimeMessageHelper;import javax.mail.MessagingException;import javax.mail.internet.MimeMessage;import java.io.File;@SpringBootTestclass EmailApplicationTests { @Autowired JavaMailSenderImpl mailSender; @Test void contextLoads() { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setSubject('你好'); mailMessage.setText('123456'); mailMessage.setTo('1550213743@qq.com'); mailMessage.setFrom('1550213743@qq.com'); mailSender.send(mailMessage); } @Test void contextLoads2() throws MessagingException { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true); helper.setSubject('你好'); helper.setText('<p style=’color:red’>這是紅色的</p>',true); helper.addAttachment('bg.jpg',new File('D:money網(wǎng)頁(yè)疫情imagesbg1.jpg')); helper.setTo('1550213743@qq.com'); helper.setFrom('1550213743@qq.com'); mailSender.send(mimeMessage); }}

5.分別對(duì)應(yīng)的結(jié)果

springboot實(shí)現(xiàn)發(fā)送郵件(QQ郵箱為例)springboot實(shí)現(xiàn)發(fā)送郵件(QQ郵箱為例)

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

標(biāo)簽: qq
相關(guān)文章:
主站蜘蛛池模板: 廉江市| 永靖县| 汝州市| 仁布县| 阳东县| 元氏县| 吉林市| 兴城市| 辰溪县| 左贡县| 绥宁县| 来安县| 新昌县| 洱源县| 定兴县| 长海县| 武胜县| 名山县| 沙河市| 富川| 清新县| 万州区| 叙永县| 安庆市| 临澧县| 呼和浩特市| 武平县| 西藏| 南和县| 惠来县| 同心县| 无锡市| 萨嘎县| 汉阴县| 鲁山县| 望江县| 山东省| 新建县| 聊城市| 襄汾县| 花莲市|