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);
    }


    }

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

  • 相关阅读:
    Linux内核编译
    Linux系统启动流程(2)
    Linux系统启动流程及grub重建(1)
    shell函数
    css基础
    前端之练习抽屉首页
    css简单分页
    mysql索引提高查询速度
    html基础
    博客园css样式代码
  • 原文地址:https://www.cnblogs.com/cx-code/p/8690267.html
Copyright © 2011-2022 走看看