github.com/go-mailx/mailx is a small Go library for sending email via swappable adapters. It provides a common MailerAdapter interface, a functional-options API for composing messages, and a Mailer that ties everything together.
go get github.com/go-mailx/mailxSee the examples directory for working examples with each adapter.
Images can be embedded in the mail and referenced from the HTML body by their Content-ID. Unlike data: URLs, this is rendered by Gmail web and mobile.
err := mailer.Send(ctx,
mailx.To("user@example.com"),
mailx.Subject("Welcome"),
mailx.HtmlBody(`<img src="cid:logo" alt="Logo">`),
mailx.Inline("logo", "image/png", logoPNG),
)The Content-ID is given without angle brackets and must be unique within the mail. Inline attachments require an adapter whose MailInstance implements mailx.InlineAttachmentAdder; otherwise Send returns mailx.ErrInlineAttachmentsNotSupported instead of sending a mail with broken images.
See pkg.go.dev/github.com/go-mailx/mailx for all message options, MailerConfig, and FromAddressFunc built-ins.
| Module | Transport |
|---|---|
github.com/go-mailx/mailx-smtp |
SMTP via go-mail |
github.com/go-mailx/mailx-ses |
AWS SES via aws-sdk-go-v2 |