zoukankan      html  css  js  c++  java
  • springboot 测试发送邮件

    首先在pom文件引入依赖:

    <!--email依赖 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>

    配置 文件:

    spring.mail.host=smtp.163.com //本人 用的是163邮箱
    spring.mail.username=****@163.com //邮箱地址
    spring.mail.password=授权码
    spring.mail.default-encoding=UTF-8
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.starttls.enable=true
    spring.mail.properties.mail.smtp.starttls.required=true

    注意:邮箱要开启pop3,smtp服务,获取授权码

     写个简单的测试类:

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class SpringbootmailApplicationTests {
    @Autowired
    private JavaMailSender mailSender;
    @Test
    public void sendSimpleMail() throws Exception {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("****@163.com");    //发送方
    message.setTo("***@qq.com");      //目标
    message.setSubject("主题:简单邮件");  
    message.setText("测试邮件内容");
    mailSender.send(message);
    }


    }

    以上是发送邮件的小测试。

  • 相关阅读:
    iOS_SN_地图的使用(3)
    iOS_SN_地图的使用(2)
    iOS_SN_百度地图基本使用(1)
    iOS_SN_CoreData(二)
    iOS_SN_CoreDate(一)封装使用
    iOS_SN_UITableView的优化
    阿里云 单表备份 恢复
    svn 彻底删除文件、文件夹
    @去除
    服务器安全保护
  • 原文地址:https://www.cnblogs.com/cx-code/p/8690267.html
Copyright © 2011-2022 走看看