SendGrid: Email Delivery

This is an Encore package for asynchronous sending emails via SendGrid using Pub/Sub and the ability to flexibly configure concurrency and retry policies.

Installation

  1. Copy over the sendgrid package directory to your Encore application.
  2. Sync your project dependencies by running go mod tidy.

SendGrid API Key

You will need an API key from SendGrid to use this package. You can get one by signing up for a free account at https://sendgrid.com/.

Once you have the API key, set it as an Encore secret using the name SendGridAPIKey:

# It is good practice to separate API keys for development and production environments $ encore secret set --dev SendGridAPIKey Enter secret value: ***** Successfully updated development secret SendGridAPIKey. # To set the API key for production environment $ encore secret set --prod SendGridAPIKey Enter secret value: ***** Successfully updated development secret SendGridAPIKey.

Please note that emails will only be sent in the production environment to avoid spending your email sending limits.

Endpoints

The sendgrid package contains the following endpoints:

  • sendgrid.Send - Send publishes an email to PubSub for further asynchronous sending using the SendGrid API.

Using the API

curl 'http://localhost:4000/sendgrid' \ -d '{ "from": { "name": "Sender", "email": "[email protected]" }, "to": { "name": "Recipient", "email": "[email protected]" }, "subject": "Sending with Twilio SendGrid is Fun", "text": "and easy to do anywhere, even with Encore", "html": "<strong>and easy to do anywhere, even with Encore</strong>" }'

Learn More