我有一个春季启动应用程序,当我运行时,我可以成功发送电子邮件消息,但是当我在我的AWS服务器上将其部署到战争时,它突然无法发送电子邮件并抛出错误:
org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsv
534-5.7.14 GyjozMVw6yK71QY1-533Cq9j3pFvZ4Qk6tvNi8jraY2Qr1olGNIenIvjiHO8PYS2clGWG_
534-5.7.14 AKcP6Ny-ZwLVxAyKeqgAnOqFPC-fC2Ha4fZuHlbiWsi8wYfeQzgoSjzBowz9R4uYWPocKY
534-5.7.14 yY7pG1k4O7ukaHccwVpLm8ypHX_MuWoiYbKFE6bSG5ht7Jps1MoPoWpE21oDtiu0udijNz
534-5.7.14 zwKkTw01RQUyNDlkJkjHWqkGQW1GM> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 s20sm9437528wmb.9 - gsmtp
代码:
@Value("${spring.mail.username}")
private String recipient;
@Autowired
private JavaMailSender javaMailSender;
public SimpleStatusObject sendEmail(SimpleEmail simpleEmail) throws MessagingException, UnsupportedEncodingException {
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(recipient);
helper.setFrom("MOJA_STRONA");
helper.setReplyTo(simpleEmail.getSenderEmail(), simpleEmail.getSenderName());
helper.setSubject(simpleEmail.getSubject());
helper.setText(simpleEmail.getMessage());
javaMailSender.send(message);
return new SimpleStatusObject(Status.SUCCESS, "message sent");
}
属性
spring.mail.host = smtp.gmail.com
spring.mail.username=email@gmail.com
spring.mail.password=mypass
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false
凭据可以,我在帐户设置中启用了较少安全的应用。我不知道这个问题是什么。
答案 0 :(得分:1)
我找到了解决方案。问题不在于春天。有时候“允许访问安全性较低的应用程序”是不够的。
以下是谷歌可能不允许访问的更多信息。 https://support.google.com/accounts/answer/6009563
首先提示:
这对我的情况有帮助。
所有学分: https://serverfault.com/questions/635139/how-to-fix-send-mail-authorization-failed-534-5-7-14