sendgrid

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sendgrid implements mail.Mailer against SendGrid's v3 HTTP API (https://docs.sendgrid.com/api-reference/mail-send/mail-send).

Usage:

m := sendgrid.New(sendgrid.Config{
    APIKey: os.Getenv("SENDGRID_API_KEY"),
    From:   "noreply@example.com",
})
err := m.Send(ctx, mail.NewMessage().
    To("user@example.com").
    Subject("Hi").
    HTML("<b>hello</b>").
    Build())

Index

Constants

View Source
const DefaultEndpoint = "https://api.sendgrid.com/v3/mail/send"

DefaultEndpoint is SendGrid's mail-send v3 endpoint.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	APIKey string
	// From is the default From address used when Message.From is empty.
	From string
	// Endpoint allows overriding the API URL (default: DefaultEndpoint).
	// Mostly useful for tests.
	Endpoint string
	// HTTPClient defaults to a 30s-timeout client.
	HTTPClient *http.Client
}

Config holds the SendGrid credentials and defaults.

type Mailer

type Mailer struct {
	// contains filtered or unexported fields
}

Mailer dispatches messages through SendGrid's HTTP API.

func New

func New(cfg Config) *Mailer

New constructs a Mailer.

func (*Mailer) Send

func (m *Mailer) Send(ctx context.Context, msg mail.Message) error

Send dispatches msg. SendGrid replies with 202 on success; anything else surfaces the response body as an error for debugging.

Jump to

Keyboard shortcuts

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