JavaMailSender邮箱配置

匿名 (未验证) 提交于 2019-12-02 21:53:52

163邮箱:

#####163邮箱######## spring.mail.host=smtp.163.com spring.mail.username=lon@163.com #163邮箱密码 spring.mail.password=qS spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true

gmail邮箱:

spring.mail.host=smtp.gmail.com spring.mail.port=465 spring.mail.username=wwh@gmail.com spring.mail.password=ndb spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.debug=true spring.mail.properties.mail.smtp.port=465 spring.mail.properties.mail.smtp.socketFactory.port=465 spring.mail.properties.mail.smtp.socketFactory.fallback=false spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory spring.mail.properties.mail.smtp.ssl.enable=true 

  

例子:

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Component;  @Component public class MailUtil {      @Autowired     private JavaMailSender javaMailSender;      @Value("${spring.mail.username}")     private String username;      public void send(String email, String subject, String body) {         SimpleMailMessage message = new SimpleMailMessage();         message.setFrom(username);         message.setTo(email);         message.setSubject(subject);         message.setText(body);         javaMailSender.send(message);     }  }

原文:https://www.cnblogs.com/wanhua-wu/p/9356834.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!