在我的spring-boot应用程序中,我可以使用org.springframework.mail.javamail.JavaMailSender
设置中的local
发送电子邮件。但是,部署到AWS
后,我无法发送电子邮件。它抛出错误,
Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbss
534-5.7.14 81d4zB6x24lGRvkee9GW4_xNnf7k6S2adqZ9bepB7TGxyKq-r_rUa225_apBlrzIRsr59E
534-5.7.14 Wo0VyVpoc6Nt-SxArWOjtMJcVw_j0heIv3DIhNg26lbkgAxJSSYw7Hdhq6DGexeWUreVmp
534-5.7.14 mj78W7HUhbjzBkiPFVwEMCtbNRmpOqzpajqEinyNmOHNCJiec3s14jzdIGz4H6iChWAFwf
534-5.7.14 lpxfs9yfXuNwgkPDd_7CVWv049PSc> 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 u51sm7087939qth.67 - gsmtp
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:424)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:307)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296)
at com.highpeak.gbi.webservices.utils.mail.GmailSenderUtil.sendMail(GmailSenderUtil.java:49)
at com.highpeak.gbi.webservices.services.impl.UserServicesImpl.lambda$sendAlertInAThread$0(UserServicesImpl.java:160)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbss
534-5.7.14 81d4zB6x24lGRvkee9GW4_xNnf7k6S2adqZ9bepB7TGxyKq-r_rUa225_apBlrzIRsr59E
534-5.7.14 Wo0VyVpoc6Nt-SxArWOjtMJcVw_j0heIv3DIhNg26lbkgAxJSSYw7Hdhq6DGexeWUreVmp
534-5.7.14 mj78W7HUhbjzBkiPFVwEMCtbNRmpOqzpajqEinyNmOHNCJiec3s14jzdIGz4H6iChWAFwf
534-5.7.14 lpxfs9yfXuNwgkPDd_7CVWv049PSc> 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 u51sm7087939qth.67 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748)
at javax.mail.Service.connect(Service.java:366)
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:501)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:421)
... 5 common frames omitted
2017-Sep-26 14:57:08.289 ERROR [Thread-7] c.h.g.w.s.i.UserServicesImpl - error
com.highpeak.gbi.webservices.uiresponse.DataException: null
at com.highpeak.gbi.webservices.utils.mail.GmailSenderUtil.sendMail(GmailSenderUtil.java:56)
at com.highpeak.gbi.webservices.services.impl.UserServicesImpl.lambda$sendAlertInAThread$0(UserServicesImpl.java:160)
at java.lang.Thread.run(Thread.java:748)
我的application.properties
文件配置为
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/gbi? useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=****
spring.datasource.password=******
spring.datasource.pool.size=20
spring.jpa.hibernate.ddl-auto=update
server.port=8090
logging.path=/ebs/logs/
logging.file=/ebs/logs/gbi.log
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{15} - %msg%n
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=*****@gmail.com
spring.mail.password=***********
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
glg.userName=********
glg.password=********
glg.senderId=*******
glg.route=*
可能是什么问题。我在gmail设置中尝试了turning-on
allow low security app access
。但它仍然无法正常工作
答案 0 :(得分:0)
似乎代码中没有问题,AWS配置中没有问题。 gmail
阻止了login
次尝试。所以我必须做两件事,
1. turn on Allow less secure apps in settings
2. go to `https://accounts.google.com/DisplayUnlockCaptcha and click continue
一切正常!!!