码迷,mamicode.com
首页 > 编程语言 > 详细

JavaMailSender邮箱配置

时间:2018-07-23 21:12:04      阅读:1763      评论:0      收藏:0      [点我收藏+]

标签:frame   port   fallback   sharp   autowire   soc   163邮箱   email   gmail   

 

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

}

 

JavaMailSender邮箱配置

标签:frame   port   fallback   sharp   autowire   soc   163邮箱   email   gmail   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!