Send an email with Thinwrap (Go)

Send transactional email via the Thinwrap Email facade in Go — one call shape for SendGrid, AWS SES, Resend and 12 more.

1. Install

go get github.com/thinwrap/notifications-go

2. Send the call

import "github.com/thinwrap/notifications-go"

e := notifications.NewEmail(notifications.SendgridConfig{
    APIKey: os.Getenv("SENDGRID_API_KEY"),
    From:   "noreply@example.com",
})

res, err := e.Send(ctx, notifications.EmailSendInput{
    To:      "user@example.com",
    Subject: "Hello from Thinwrap",
    Text:    "Hello world",
})
if err != nil {
    var ce *notifications.ConnectorError
    if errors.As(err, &ce) {
        log.Printf("%s: %s", ce.ProviderCode, ce.ProviderMessage)
    }
    return
}

// res.Status is sent | queued | rejected | suppressed | unknown
// res.ProviderMessageID is the upstream message id, or ""
fmt.Println(res.Status, res.ProviderMessageID)

Same code works for all supported providers — just change the provider ID.