Search code examples
javaspring-bootherokugmail

Send email with Spring Boot app in Heroku


I've successfully deployed a Spring Boot app on Heroku. This app should send emails after an user fills a form.

The problem is that, in local it works, but in Heroku the app always throws AuthenticationFailedException because it is trying to sign in with my Gmail account from Heroku's server in another country.

My Gmail account does not have two factor authentication and less secure app option is enabled.

How can I solve this? How can my Spring Boot app in a server abroad sign in with my Gmail account from another country?


Solution

  • How can I solve this?

    By not using Gmail. It's not meant for automated, programmatic email delivery.

    Instead, use something like SendGrid or Mailgun. These services are designed for programmatic mail delivery, and both are available as official Heroku addons with free tiers.