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