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

Why my email sending doesn't work on deployed website but it works on my localhost?

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

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

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

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 部署的):

谢谢!

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

如错误消息所述,有一个 AuthenticationException,错误消息要求通过浏览器登录。

由于 2FA 已关闭,最可能的原因是他们想要显示验证码,这需要人工交互。目标帐户上的 link I found suggests that by visiting https://accounts.google.com/DisplayUnlockCaptcha 将允许您手动清除验证码,然后它会起作用。

但是我不相信手动清除验证码就足够了,因为它随时可能回来。似乎正确的方法是启用 2FA,并使用 application specific passwords.