Flask接口签名sign原理与实例代码浅析
438
2022-12-03
springboot实现发送邮件(QQ邮箱为例)
本文实例为大家分享了springboot实现发送邮件的具体代码,供大家参考,具体内容如下
1.引入依赖
2.找到qq邮箱,开启smtp服务,这里生成你的密码,复制第三步用
3.password里输入你获取到的密码(重点:这里一定不能错)
spring.mail.username=1550213743@qq.com
spring.mail.password=********
spring.mail.host=smtp.qq.com
#开启加密验证
spring.mail.properties.mail.smtp.ssl.enable=true
4.EmailApplicationTests类里进行测试, contextLoads为简单的发送,仅限于文本。contextLoads2为复杂,可以发送图片,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;
@SpringBootTest
class 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("
这是红色的
helper.addAttachment("bg.jpg",new File("D:\\money\\网页\\疫情\\images\\bg1.jpg"));
helper.setTo("1550213743@qq.com");
helper.setFrom("1550213743@qq.com");
mailSender.send(mimeMessage);
}
}
5.分别对应的结果
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~