-
Get SendGrid Credentials.
Create an account on SendGrid and verify a "single sender" email address that the function will use for sending emails.
Add the following 2 environment variables to a file named
.env.development
. You'll need these for the function to be able to send emails:SENDGRID_API_KEY
: An SendGrid API Key with full access. SendGrid DocsSENDGRID_AUTHORIZED_EMAIL
: the "single sender" the email address you verified with SendGrid SendGrid Docs
Read more about how Gatsby handles
.env
files and environment variables in the Gatsby DocsYou'll also want to add these as environment variables when deploying to Gatsby Cloud. Don't forget to add them to the Preview variables if you plan to add a CMS preview integration.
-
Start developing.
To get started, run
npm install
to install all necessary packages.cd examples/functions-sendgrid-email npm install npm run develop
-
Open the code and start customizing!
Your site is now running at http://localhost:8000! You can use the UI on the index page to test the functions or directly access them at http://localhost:8000/api/sendgrid
Edit
src/pages/index.js
to see your site update in real-time! -
Deploy
You can deploy this example on Gatsby Cloud by copying the example into a new repo and connecting that to Gatsby Cloud.