Prerequisites
Before we begin, we’ll need to installnodemailer, and store sensitive values inside a .env file.
Install Nodemailer
Install Nodemailer types (Optional)
If you’re using TypeScript in your project, make sure to download@types/nodemailer as well:
Setup environment varaibles
It is best practise to store sensitive values inside an.env file, add the following values to your env file:
.env
Sending Transactional emails
Now our project is setup, we can send transactional emails using Nodemailer. First, we need to setup thetransporter which holds the connection information and decide what secure method to use:
Using STARTTLS
To use STARTTLS, set your port to587 and set secure to false:
Using SSL
To use SSL, set your port to465 and set secure to true:
Sending mail!
Now that thetransporter has been initalised, we can send some mail!