Using the Netlify Lambda Function for Sendgrid Mailing List
A "ready to deploy" serverless mailing list subscription API endpoint using a Netlify function and the Sendgrid API. Collect emails and optionally, a welcome messages with a single
POST HTTP request. Based on code from ndethore.
- Sendgrid Account + Sendgrid API Key
- Create a verified sender
- (Optional) Create a welcome email template and get the ID for it
The Deploy button will ask for your Sendgrid API keys and other settings upon installation or they can be entered in the Deploy Settings in your Netlify admin panel. Add the following environment variables for the function:
It is only mandatory to enter your Sendgrid API Key. If you would like to send a welcome email, then fill out the rest of the environment variables. Turn on the email newsletter signup box by going in the Netlify CMS backend and editing the Setup collection. Under Site Info, you will find a switch to turn it on.
The signup box will be activated and you are all set!
Add the query parameter
?welcome_email=true to email newly added recipients using the specified Sendgrid template ID.