mailx

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 4 Imported by: 0

README

mailx

Go Reference

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.

Install

go get github.com/go-mailx/mailx

Usage

See the examples directory for working examples with each adapter.

API

See pkg.go.dev/github.com/go-mailx/mailx for all message options, MailerConfig, and FromAddressFunc built-ins.

Adapters

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FromAddressFunc

type FromAddressFunc = func(ctx context.Context, mail Mail) string

func MailOverrideFromAddress

func MailOverrideFromAddress() FromAddressFunc

func StaticFromAddress

func StaticFromAddress(address string) FromAddressFunc

type Mail

type Mail struct {
	To           []string
	From         *mail.Address
	Bcc          []string
	ReplyTo      string
	Subject      string
	HtmlBodyFunc func() (string, error)
	TextBodyFunc func() (string, error)
}

func New

func New(opts ...MailOpt) Mail

type MailInstance

type MailInstance interface {
	To([]string) error
	From(string) error
	Bcc([]string) error
	ReplyTo(string) error
	Subject(string) error
	HtmlBody(string) error
	TextBody(string) error
	Send(context.Context) error
}

type MailOpt

type MailOpt func(mail *Mail)

func Bcc

func Bcc(to ...string) MailOpt

func From

func From(from mail.Address) MailOpt

func HtmlBody

func HtmlBody(body string) MailOpt

func HtmlBodyTemplate

func HtmlBodyTemplate(tmpl *template.Template, data any) MailOpt

func ReplyTo

func ReplyTo(to string) MailOpt

func Subject

func Subject(subject string) MailOpt

func TextBody

func TextBody(body string) MailOpt

func To

func To(to ...string) MailOpt

type Mailer

type Mailer struct {
	MailerAdapter
	Config *MailerConfig
}

func (*Mailer) Send

func (m *Mailer) Send(ctx context.Context, opts ...MailOpt) error

type MailerAdapter

type MailerAdapter interface {
	NewMail(context.Context) (MailInstance, error)
}

type MailerConfig

type MailerConfig struct {
	FromAddressSrc []FromAddressFunc
}

func (*MailerConfig) GetActualFromAddress

func (mc *MailerConfig) GetActualFromAddress(ctx context.Context, mail Mail) string

type Noop

type Noop struct{}

func (*Noop) Bcc

func (n *Noop) Bcc([]string) error

func (*Noop) From

func (n *Noop) From(string) error

func (*Noop) HtmlBody

func (n *Noop) HtmlBody(string) error

func (*Noop) NewMail

func (n *Noop) NewMail(context.Context) (MailInstance, error)

func (*Noop) ReplyTo

func (n *Noop) ReplyTo(string) error

func (*Noop) Send

func (n *Noop) Send(context.Context) error

func (*Noop) Subject

func (n *Noop) Subject(string) error

func (*Noop) TextBody

func (n *Noop) TextBody(string) error

func (*Noop) To

func (n *Noop) To([]string) error

Jump to

Keyboard shortcuts

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