with SendGrid's Email API and Node.js!
Once you create a Sendgrid account or login, click on the Email API tab on the navigation bar on the left. This will open up two options: Dynamic Templates and Integration Guide.
Click on Integration Guide and choose the Web API as your setup method.
Choose a language you are comfortable with. I found tutorials with Node.js so that is what I went with.
After choosing a language, Sendgrid gives you easy and simple documentation on how to use their API. I will copy its steps below for your convenience.
Sendgrid's library requires Node.js version 0.10, 0.12, or 4.
Click on the blue button after you name your API key in step 2. This will generate your key and update the code block in step 3.
Copy the code block from step 3 and run it in your shell.
echo "export SENDGRID_API_KEY='your-key-here'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
Each time you want to run your JS script on a fresh shell, you need to run source ./sendgrid.env
first to activate your API key. The code above basically writes your API key in a env file called sendgrid.env, so make sure to preserve that file!
Npm comes installed with Node.js since node version 0.8.x, therefore you likely already have it.
npm install --save @sendgrid/mail
Sendgrid gives you the minimum code needed to send a single email. But if you want to use a CSV for a mass email and/or send a PDF, take a look at my index.js!