Send an email with SendGrid in Node.js
This is an example of how to send an email. To run this script you should:
- Download the index.js and package.json files
- Install the dependencies with
- Get a SendGrid API key from your SendGrid dashboard
- Verify an email address or authenticate a domain so that you can send emails with SendGrid
- Set the credentials and other variables in the environment and run the script:
SENDGRID_API_KEY=xyz789 \ FROM_EMAILemail@example.com \ TO_EMAILfirstname.lastname@example.org \ node index.js
Alternatively, you can replace the calls to
process.env with your variables.
Run the script and you will receive an email.