spring-boot-starter-mail技术总结

1. spring-boot-starter-mail技术总结

1.1. 配置读取类SMTPTransport

  1. 在application中需要配置的信息,在此类中都可以看到,可以在此类打断点查看

1.2. 配置文件

spring.mail.host=smtp.163.com
spring.mail.username=15068610616@163.com
spring.mail.password=xxx
# 启动ssl
spring.mail.properties.mail.smtp.ssl.enable=true

# 启动tls
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000

1.3. 测试代码

@RunWith(SpringRunner.class)
@SpringBootTest
public class ZookeeperApplicationTests {

    @Autowired
    private JavaMailSender mailSender;

    @Test
    public void testMail() throws MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        //发件人
        helper.setFrom("15068610616@163.com");
        //收件人
        helper.setTo("15068610616@163.com");
        //标题
        helper.setSubject("subject");
        //文本
        helper.setText("message text");
        //附件
        helper.addAttachment("downFile",new File("D:\\cygwin64\\home\\workspace3\\learn-demo\\zookeeper\\src\\test\\java\\com\\tzxylao\\design\\ZookeeperApplicationTests.java"));
        mailSender.send(mimeMessage);
    }

}

转载于:https://www.cnblogs.com/sky-chen/p/10710516.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值