SpringBoot 发送邮件
2021-06-06 09:02
标签:xxx message 邮件 java 加密 attach 授权 wired intern 感谢你一生的陪伴 +" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + "+ SpringBoot 发送邮件 标签:xxx message 邮件 java 加密 attach 授权 wired intern 原文地址:https://www.cnblogs.com/kikyoqiang/p/14615271.htmlSpringBoot发送邮件
1、pom
2、yml
spring.mail.username=90xxxxx31@qq.com
spring.mail.password=qq邮箱授权码
spring.mail.host=smtp.qq.com
#开启加密验证
spring.mail.properties.mail.smtp.enable=true
3、mailSender
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.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
@SpringBootTest
class SpringbootTaskApplicationTests {
@Autowired
JavaMailSenderImpl mailSender;
@Test
void contextLoads() {
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setSubject("桔梗,你好");
simpleMailMessage.setText("感谢你一生的陪伴");
simpleMailMessage.setSubject("桔梗");
simpleMailMessage.setTo("26xxxxx83@qq.com");
simpleMailMessage.setFrom("90xxxxx31@qq.com");
mailSender.send(simpleMailMessage);
}
@Test
void contextLoads2() throws MessagingException {
//一个复杂的邮件
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setSubject("桔梗,你好");
helper.setText("
下一篇:数组的应用