Springboot-mail &网易邮箱 465端口

  # 邮箱配置
spring:  
  mail:
    password: password
    username: 邮箱@163.com
    default-encoding: UTF-8
    host: smtp.163.com
    properties:
      mail:
        smtp:
          starttls:
            enable: true
            required: true
          auth: true
          socketFactory:
            port: 465
            class: javax.net.ssl.SSLSocketFactory
 @Async
    public void send(String email) {
     
        String code = RandomUtil.produceNumber(6);
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("邮箱@163.com");
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("主题");
        String context = "您的验证码为" + code + ",5分钟内有效。如非本人操作,请忽略";
        simpleMailMessage.setText(context);
        javaMailSender.send(simpleMailMessage);//发送
    }
 		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

setFrom中的邮箱和配置中的邮箱一致

你可能感兴趣的:(问题笔记,工作,java,javamail)