高老师好
@Autowired
private JavaMailSender mailSender;
//复杂邮件
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,true);
messageHelper.setFrom("476877476@qq.com");
messageHelper.setTo("812343497@qq.com");
messageHelper.setSubject("Happy New Year");
messageHelper.setText("新年快乐!");
messageHelper.addInline("doge.png", new File("D:\eladmin\file\图片\1.png"));
messageHelper.addAttachment("work.png", new File("D:\eladmin\file\图片\1.png"));
mailSender.send(mimeMessage);
yml
QQ邮箱配置
mail:
host: smtp.qq.com #发送邮件服务器
username: 476877476@qq.com #发送邮件的邮箱地址
password: zshx123123tcbjjg #客户端授权码,不是邮箱密码,这个在qq邮箱设置里面自动生成的
properties.mail.smtp.port: 465 #端口号465或587
from: 476877476@qq.com # 发送邮件的地址,和上面username一致可以任意
properties.mail.smtp.starttls.enable: true
properties.mail.smtp.starttls.required: true
properties.mail.smtp.ssl.enable: true
default-encoding: utf-8