This error occurs on Node.js applications deployed on Heroku without proper configuration of environment variables. Additionally, you may also run into this error due to invalid configurations.
Resolving the error by updating configurations
Ensure that you have configured Nodemailer successfully. You may use the snippet shown below as a guide for configuring Nodemailer.
Additionally, if you are using Google SMTP servers, ensure that you have turned on Less Secure Sign In. For users that use Office 365, ensure that SMTP authentication is turned on for your Microsoft account.
Resolving the error in Heroku
You will need to configure your Nodemailer environment variables in the deployed Heroku application.
To do so, first, log in to your Heroku console. Afterward, click on the deployed application and click "Settings." You will see the output shown below.
Figure 01 - Heroku application settings
Hereafter, click on "Reveal Config Vars." It will display the output shown below.
Figure 02 - Viewing config variables in the Heroku console
Then, add the environment variables that you use with Nodemailer.
Figure 03 - Adding config variables to Heroku
Finally, re-rerun the application to see the emails getting sent successfully!
Resolving steps if none of the above works
If none of the actions work for you, ensure that you have provided the correct username/password, port, and protocol. Additionally, if you use
dotenv to load the environment file, ensure that you properly access the configurations.
View all errors