zoukankan      html  css  js  c++  java
  • 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 {
    
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> JavaMailSender mailSender;
    
    <span class="hljs-meta">@Test</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> testMail() <span class="hljs-keyword">throws</span> MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = <span class="hljs-keyword">new</span> MimeMessageHelper(mimeMessage, <span class="hljs-literal">true</span>);
        <span class="hljs-comment">//发件人</span>
        helper.setFrom(<span class="hljs-string">"15068610616@163.com"</span>);
        <span class="hljs-comment">//收件人</span>
        helper.setTo(<span class="hljs-string">"15068610616@163.com"</span>);
        <span class="hljs-comment">//标题</span>
        helper.setSubject(<span class="hljs-string">"subject"</span>);
        <span class="hljs-comment">//文本</span>
        helper.setText(<span class="hljs-string">"message text"</span>);
        <span class="hljs-comment">//附件</span>
        helper.addAttachment(<span class="hljs-string">"downFile"</span>,<span class="hljs-keyword">new</span> File(<span class="hljs-string">"D:\cygwin64\home\workspace3\learn-demo\zookeeper\src\test\java\com\tzxylao\design\ZookeeperApplicationTests.java"</span>));
        mailSender.send(mimeMessage);
    }
    

    }


    原文地址:https://www.cnblogs.com/sky-chen/p/10710516.html

  • 相关阅读:
    计算机速成课 第十一集 编程语言发展史
    计算机速成课 第十集 早期的编程方式
    Sharepoint2013操作文档库内容的相关操作
    IE6 css fixed
    Sharepoint2013站点503错误的解决方法(图解)
    发布Sharepoint2013相关的WebService服务
    Spring 读书笔记Spring容器(二)
    (转)UML类图与类的关系详解
    (转)C# 操作 Excel 颜色索引对照
    (转)Silverlight显示本地图片、Stream转Byte数组
  • 原文地址:https://www.cnblogs.com/jpfss/p/11271336.html
Copyright © 2011-2022 走看看