java - org.springframework.mail.MailAuthenticationException:身份验证失败;嵌套异常是 javax.mail.AuthenticationFailedException: ;
问题描述
我正在尝试从我的 springboot 应用程序发送电子邮件并收到以下错误
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: ;
nested exception is:
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketTimeoutException: Read timed out] with root cause
这就是我的属性文件的样子
应用程序属性
spring.mail.properties.mail.smtp.connecttimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.host=smtp.office365.com
spring.mail.password=<passwordhere>
spring.mail.port=587
spring.mail.username=kshitij_kohli@intuit.com
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smpt.auth=true
电子邮件发件人.java
package com.intuit.utils;
import javax.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
@Service
public class EmailSender {
@Value("${spring.mail.username}")
private String from;
@Autowired
private JavaMailSender javaMailSender;
public void sendMail(String to) throws MessagingException, javax.mail.MessagingException {
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper;
helper = new MimeMessageHelper(message, true);//true indicates multipart message
helper.setFrom(from);
String subject = "some subbject";
String body = "some body";
helper.setSubject(subject);
helper.setTo(to);
helper.setText(body, true);//true indicates body is html
javaMailSender.send(message);
}
}
我似乎缺少一些身份验证。我必须使用该应用程序向我组织的公司帐户发送电子邮件。
解决方案
似乎组织阻止了身份验证,并且邮件需要一些特定于组织的步骤才能通过 - 属性文件本身没有问题。
推荐阅读
- python - 无法安装噪声模块
- mysql - MySQL:BTREE 慢速索引路径(表大小:723704015 行)
- python - 创建一个函数,该函数接收名称为数组的字符串,然后打印每个元素 [python]
- node.js - TypeError:Router.use() 需要一个中间件函数,但有一个未定义的
- c# - 使用 iTextSharp 将图像插入 PDF 表单
- linux - bash 中过度设计的 checkroot
- java - swapWords 方法不返回修改后的 ArrayList
在爪哇 - android - 颤振:图像 BoxFit.cover 在堆栈中不起作用
- twilio - 通过 Twilio 获取 API
- html - thead 和 tbody 之间的边框和边距