邮件任务
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> <scope>test</scope> </dependency>
配置文件
spring: mail: username: *********** password: ********* (这是qq邮箱的授权码) host: smtp.qq.com spring.mail.properties.mail.smtp.ssl.enable=true
测试类
@Autowired(required = false) JavaMailSenderImpl mailSender; @Test public void contextLoads() { SimpleMailMessage message = new SimpleMailMessage(); //邮件设置 message.setSubject("通知-今晚开会"); message.setText("今晚7:30开会"); message.setTo("**************"); message.setFrom("**************"); mailSender.send(message); } @Test public void test02() throws Exception{ //1、创建一个复杂的消息邮件 MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); //邮件设置 helper.setSubject("测试"); helper.setText("<b style='color:red'>今天 7:30 开会</b>",true); helper.setTo("***************"); helper.setFrom("**************"); //上传文件 helper.addAttachment("nginx.md",new File("C:\\Users\\asus\\Desktop\\nginx.md")); mailSender.send(mimeMessage); }
结果:
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!