zoukankan      html  css  js  c++  java
  • JavaMailSender邮箱配置

    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);
        }
    
    }
  • 相关阅读:
    JSP学习(一)
    Servlet学习(五)——通过response设置响应体及中文乱码问题
    SQLServer -------- 不展示后两位小数
    MySQL ------ 数据库操作 (二)
    MySQL ------ CentOS 上 安装mysql (一)
    java ----------- I/O (六) 标准输入输出流
    java ----- I/O (五) 数据流读写文件
    Linux ------ centos 上安装JDK
    iis 中找不到安装的 .net 4.0
    清理C 盘
  • 原文地址:https://www.cnblogs.com/wanhua-wu/p/9356834.html
Copyright © 2011-2022 走看看