Skip Navigation

Scott Spence

Sending Emails With Twilio SendGrid

2 min read

This is a private post 🤫

This means it's probably incomplete and not intended for public consumption.

Hey! Thanks for stopping by! Just a word of warning, this post is about 3 years old, . If there's technical information in here it's more than likely out of date.

Now I have a super sweet email pipeline for sending weekly emails thanks to Sam Larsen-Disney I’m going to document what I’ve learnt and what Sam taught me. (same thing, I guess) 😊

First up, I’d like to thank Sam for his patience walking me through this a couple of times over now.

If you are looking to do something similar then the hope is that this can give you an idea of what you need to do.

Prerequisites

There’s no real prerequisites here I’d say, having an email from your custom domain is a nice touch but as far as I know not essential.

If you want to set up a custom email address to send from, I have done this in the past with Zoho and you can check Setting up a Custom Email with Zoho for details on that and also Setting up ProtonMail with Vercel they’re both for Vercel via the Vercel CLI.

I’ll need a from on my site to collect the information with, I use Kwes Forms which isn’t completely redundant a this point as it has great validation that I can use.

Also it was what I had in place already, if you’re interested in Kwes Forms take a look at the video here:

There are also other videos from friends of mine detailing the same process:

Add contacts to SendGrid

This is the code Sam kindly furnished me with, this can be gleaned from SendGrid as well.

/**
 * This is what is used to send the contact to SendGrid
 * the `list_ids` is from my contacts list in SendGrid
 * that is the id of my Newsletter list
 */

export default async function happyForm(email, name, list) {
  await fetch('https://api.sendgrid.com/v3/marketing/contacts', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${process.env.GATSBY_SENDGRID_API_KEY}`,
    },
    body: JSON.stringify({
      list_ids: [list],
      contacts: [
        {
          email,
          first_name: name,
        },
      ],
    }),
  })
}

To do that, if you create a new list in your contacts then

sendgrid empty contact list

There's a reactions leaderboard you can check out too.

Copyright © 2017 - 2024 - All rights reserved Scott Spence