sendgrid

package
v0.0.0-...-8b33263 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 8 Imported by: 0

README

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": "sender@example.com"
    },
    "to": {
        "name": "Recipient",
        "email": "recipient@example.com"
    },
    "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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Emails = pubsub.NewTopic[*EmailPreparedEvent]("emails", pubsub.TopicConfig{
	DeliveryGuarantee: pubsub.AtLeastOnce,
})

Functions

This section is empty.

Types

type Address

type Address struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type EmailPreparedEvent

type EmailPreparedEvent struct {
	From             mail.Email
	Subject          string
	To               mail.Email
	PlainTextContent string
	HTMLContent      string
}

type SendParams

type SendParams struct {
	From    Address `json:"from"` // sender email address
	To      Address `json:"to"`   // recipient email address
	Subject string  `json:"subject"`
	Text    string  `json:"text"`
	Html    string  `json:"html"`
}

type SendResponse

type SendResponse struct {
	MessageID string `json:"message_id"` // Message ID in PubSub
}

func Send

func Send(ctx context.Context, params *SendParams) (*SendResponse, error)

Send publishes an email to PubSub for further asynchronous sending using the SendGrid API. https://docs.sendgrid.com/api-reference/mail-send/mail-send

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL