Help us shape the future of Go! Take the 2026 Go Developer Survey

awsmail

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 8 Imported by: 0

README

Amazon SES Mail Driver

arkoren.dev/driver/aws/awsmail implements mail.Driver with the Amazon SES v2 Go SDK. It uses the AWS default credential chain and supports optional region selection. Every valid portable message is serialized as raw RFC 5322 MIME, so the driver supports text and HTML bodies, To/CC/BCC, Reply-To, regular attachments, and inline CID attachments. A successful submission returns the SES MessageId as mail.Receipt.ID.

import "arkoren.dev/driver/aws/awsmail"

driver, err := awsmail.New(ctx, func(mailer *awsmail.Builder) {
	mailer.Region("eu-west-1")
})

New runs callbacks directly once, synchronously in order on one fresh draft before loading AWS configuration. Nil entries panic; expanded nil/empty slices omit edits. Region returns the draft; retaining it cannot change the completed client. NewFrom(client) has no optional settings or callback; the client stays caller-owned.

Install with go get arkoren.dev/driver/aws. Supply a caller context ctx, check the constructor error, and wrap the driver with mail.New. Your identity must be verified and IAM credentials must allow ses:SendEmail; sandbox accounts also restrict recipients. Success means acceptance, not delivery. AWS SDK retry policies remain in effect. See SES setup and sending and the API reference.

Documentation

Overview

Package awsmail provides an Amazon SES v2 mail.Driver. New loads AWS configuration after invoking ordered Builder callbacks once. Nil callbacks panic; expanded nil/empty slices omit edits. NewFrom wraps an already configured native client without settings or lifecycle ownership.

Example:

driver, err := awsmail.New(ctx, func(mailer *awsmail.Builder) {
	mailer.Region("eu-west-1")
})
if err != nil {
	return err
}
_ = driver

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is the mutable SES construction draft. New invokes callbacks once, in order, before loading AWS configuration; retaining a draft does not retain the resulting client. Native clients supplied to NewFrom need no settings.

Example:

configure := func(mailer *Builder) {
	mailer.Region("eu-west-1")
}
driver, err := New(ctx, configure)
if err != nil {
	return err
}
_ = driver

func (*Builder) Region

func (mailer *Builder) Region(region string) *Builder

Region selects an AWS region, or the default chain when empty. It replaces the previous setting and returns the same construction draft.

Example:

configure := func(mailer *Builder) {
	mailer.Region("eu-west-1")
}
driver, err := New(ctx, configure)
if err != nil {
	return err
}
_ = driver

type BuilderFunc

type BuilderFunc = func(*Builder)

BuilderFunc edits the SES construction draft once, before AWS configuration loading. Nil entries panic; native conversion through NewFrom needs no draft.

Example:

var configure awsmail.BuilderFunc = func(mailer *awsmail.Builder) {
	mailer.Region("eu-west-1")
}
driver, err := awsmail.New(ctx, configure)
if err != nil {
	return err
}
_ = driver

type Driver

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

Driver submits mail.Message values through Amazon SES v2. It borrows its native client and reports submission acceptance, not delivery. Use the mail facade when you need sender defaults and operation observations.

Example:

driver := awsmail.NewFrom(sesv2.NewFromConfig(cfg))
mailer := mail.New(driver)
_ = mailer

func New

func New(ctx context.Context, configure ...BuilderFunc) (*Driver, error)

New creates an SES v2 Driver using the AWS default credential chain. It runs callbacks directly once in order before loading credentials. Nil entries panic; expanded nil or empty slices supply no callbacks.

Example:

driver, err := awsmail.New(context.Background(), func(mailer *awsmail.Builder) {
	mailer.Region("eu-west-1")
})
if err != nil {
	return err
}
_ = driver

func NewFrom

func NewFrom(client client) *Driver

NewFrom wraps an existing SES v2 client without copying or closing it. The client already carries Region and other native settings, so this constructor has no optional settings or construction callbacks.

Example:

driver := awsmail.NewFrom(sesv2.NewFromConfig(cfg))
_ = driver

func (*Driver) Client

func (driver *Driver) Client() *sesv2.Client

Client returns the underlying SES client, or nil when the driver was built from a test double. The client remains shared and caller-owned; direct native sends bypass the facade's validation, events, and telemetry.

Example:

if native := driver.Client(); native != nil {
	_ = native.Options().Region
}

func (*Driver) Send

func (driver *Driver) Send(ctx context.Context, message mail.Message) (mail.Receipt, error)

Send validates and serializes an immutable mail.Message as raw MIME for SES v2. The sender must be set. All recipients, including BCC, enter the SES envelope; MIME encoding keeps BCC out of the message headers. Validation, encoding, and provider failures return an empty receipt and wrapped errors.

Example using a configured driver and request context:

message := mail.NewMessage(mail.Recipients{
	To: []mail.Address{{Email: "person@example.com"}},
}, mail.Body{Text: "Hello."}, func(letter *mail.MessageBuilder) {
	letter.From(mail.Address{Email: "sender@example.com"})
})
receipt, err := driver.Send(ctx, message)
if err != nil {
	return err
}
_ = receipt.ID

Jump to

Keyboard shortcuts

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