添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
非常酷的红茶  ·  vue改变当前url ...·  1 年前    · 
坚强的铁板烧  ·  hibernate - No ...·  1 年前    · 

use microsoft mail account in java program can not send out email

I have enabled smtp auth

configuration:

spring.mail.default-encoding=utf-8

spring.mail.host=smtp.office365.com

spring.mail.port=587

spring.mail.username=****

spring.mail.password=****

spring.mail.protocol=smtp

spring.mail.properties.mail.smtp.auth=true

spring.mail.properties.mail.transport.protocol=smtp

spring.mail.properties.mail.smtp.starttls.enable=true

spring.mail.properties.mail.smtp.ssl.socketFactory.class=com.sun.mail.util.MailSSLSocketFactory

spring.mail.properties.mail.smtp.ssl.socketFactory.fallback=false

spring.mail.properties.mail.debug=true

code:

@RequestMapping("/simple")

public void SendSimpleMessage(MailRequest mailRequest) {

SimpleMailMessage message = new SimpleMailMessage();
//邮件发件人
message.setFrom(sendMailer);
//邮件收件人 1或多个
message.setTo(mailRequest.getSendTo().split(","));
//邮件主题
message.setSubject(mailRequest.getSubject());
//邮件内容
message.setText(mailRequest.getText());
//邮件发送时间
message.setSentDate(new Date());
javaMailSender.send(message);