为什么我的电子邮件发送在已部署的网站上不起作用,但在我的本地主机上却可以?

问题描述 投票:0回答:3

几周前,我的电子邮件可以从我为表弟的企业创建的网站完美发送,但现在她告诉我,她的客户每次尝试预约时都会遇到此错误。

现在我已经开始调试它,我检查了我用于发送的 gmail 是否允许每个应用程序访问它,我再次检查了 spring boot 应用程序属性等。在我的本地主机上测试它时,它发送电子邮件,但在部署的网站上,它给出了下图中的错误...同样,两个月前,当我进行最后一次检查时,它工作正常。它仍然工作正常,但只是在我的本地主机上。

这就是我的应用程序属性的样子:

spring.mail.host=smtp.gmail.com
spring.mail.username=..
spring.mail.password=..
spring.mail.port=587
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000

这是每个人都会遇到的错误的屏幕截图(网站是用heroku部署的):

谢谢!

java spring-boot smtp gmail
3个回答
1
投票

正如错误消息所述,有一个

AuthenticationException
,并且错误消息要求通过浏览器登录。

由于 2FA 已关闭,最可能的原因是他们想要显示验证码,这需要人工交互。我发现的链接表明,通过访问目标帐户上的https://accounts.google.com/DisplayUnlockCaptcha,您可以手动清除验证码,然后它就可以工作了。

但是我不相信手动清除验证码就足够了,因为它可能随时会回来。看来正确的方法是启用 2FA,并使用应用程序特定密码


0
投票
You have to Pass Username(Gmail Id) and Gmail Mail APi Generated Password
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000

0
投票

当我发送电子邮件时,在 locahost 中接收 otp 的时间是正确的,但在服务器上,接收 otp 的时间不正确。有什么帮助吗??

© www.soinside.com 2019 - 2024. All rights reserved.