使用 Spring 在 Heroku 中启动应用程序发送电子邮件

Send email with Spring Boot app in Heroku

我已经在 Heroku 上成功部署了 Spring 启动应用程序。此应用应在用户填写表格后发送电子邮件。

问题是,在本地它可以工作,但在 Heroku 中,应用程序总是抛出 AuthenticationFailedException 因为它试图从另一个国家的 Heroku 服务器使用我的 Gmail 帐户登录。

我的 Gmail 帐户没有双因素身份验证,并且启用了不太安全的应用程序选项。

我该如何解决这个问题?我的 Spring 在国外服务器上启动的应用程序如何使用我在另一个国家的 Gmail 帐户登录?

How can I solve this?

不使用 Gmail。它不适用于自动、程序化的电子邮件传送。

而是使用 SendGrid or Mailgun. These services are designed for programmatic mail delivery, and both are available as official Heroku addons with free tiers.