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 ¶
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 ¶
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 ¶
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