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

}

 

相关文章:

  • 2021-06-15
  • 2021-12-19
  • 2021-07-04
  • 2021-10-09
  • 2021-12-18
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2021-07-27
  • 2021-12-16
  • 2021-07-13
  • 2021-05-21
  • 2021-12-15
  • 2022-01-08
  • 2021-06-16
相关资源
相似解决方案