email

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package email defines a provider-agnostic Sender interface for transactional email and the value types that flow through it.

The interface is intentionally narrow. It covers the fields every major provider (SES, Postmark, Resend, Mailgun, SMTP2GO, plain SMTP) supports: recipients, subject, text+html bodies, attachments, inline images, custom headers, and free-form tags for correlation. Provider-specific features (templates, per-recipient substitutions, scheduled send, tracking flags) live either in custom headers, tags, or in your app's own adapter code — not in this interface.

Typical wiring:

var sender email.Sender
if os.Getenv("EMAIL_MOCK") == "true" {
    sender = emailmock.New(os.Getenv("HAMR_DEV_URL"))
} else {
    sender = myapp.NewResendSender(resendAPIKey)
}

Both the mock and any real adapter satisfy email.Sender, so the rest of the app depends only on this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Name  string
	Email string
}

Address is a single RFC 5322 mailbox. Name is optional.

func Addr

func Addr(name, email string) Address

Addr constructs an Address. Pass an empty name for a bare email.

type Attachment

type Attachment struct {
	Filename    string
	ContentType string // RFC 2046 media type; defaults to application/octet-stream if empty
	Data        []byte
	ContentID   string // only meaningful for Message.Inline entries
}

Attachment is a file attached to a Message. For inline images referenced from HTML via cid:, set ContentID and place the Attachment in Message.Inline.

type Message

type Message struct {
	From        Address
	To          []Address
	Cc          []Address
	Bcc         []Address
	ReplyTo     *Address // nil if not overriding From
	Subject     string
	Text        string            // plaintext body
	HTML        string            // html body
	Attachments []Attachment      // downloadable files
	Inline      []Attachment      // inline images; ContentID must be set and referenced as cid:<ContentID> in HTML
	Headers     map[string]string // custom headers (List-Unsubscribe, X-*, In-Reply-To, etc.)
	Tags        map[string]string // free-form metadata for provider correlation
}

Message is the input to Sender.Send. Exactly one of Text or HTML should be set for single-part messages; setting both produces a multipart/alternative.

type Result

type Result struct {
	ID string // provider-assigned message id (empty if the backend does not return one)
}

Result describes a successfully-sent message.

type Sender

type Sender interface {
	Send(ctx context.Context, msg Message) (*Result, error)
}

Sender sends an email through some backend (real provider, mock, SMTP, etc.). Implementations must be safe for concurrent use.

Jump to

Keyboard shortcuts

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