Documentation
¶
Overview ¶
Package postmand sends transactional and marketing email through Mailpit, SMTP, or a logging sender, and renders the HTML/text template pairs exported by React Email.
Index ¶
- Variables
- func HTMLToText(htmlContent string) (string, error)
- func IsRetryable(err error) bool
- func IsValidationError(err error) bool
- func SendMarketing(ctx context.Context, data MarketingData, sender MarketingSender) error
- func SendTransactional(ctx context.Context, data TransactionalData, sender TransactionalSender) error
- type Attachment
- type Log
- type Mailpit
- type MailpitConfig
- type MarketingData
- type MarketingPayload
- type MarketingSender
- type PermanentError
- type SMTP
- type SMTPConfig
- type SMTPTLSMode
- type Templates
- type TemporaryError
- type TransactionalData
- type TransactionalPayload
- type TransactionalSender
- type Transformer
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsubscribeURLRequired = errors.New("marketing emails require unsubscribe URL") ErrMissingRecipient = errors.New("missing recipient email address") ErrMissingSender = errors.New("missing sender email address") ErrMissingSubject = errors.New("missing email subject") ErrMissingHTMLBody = errors.New("missing email HTML body") )
Functions ¶
func HTMLToText ¶
func IsRetryable ¶
func IsValidationError ¶
func SendMarketing ¶
func SendMarketing( ctx context.Context, data MarketingData, sender MarketingSender, ) error
func SendTransactional ¶
func SendTransactional( ctx context.Context, data TransactionalData, sender TransactionalSender, ) error
Types ¶
type Attachment ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log logs messages instead of delivering them. It makes production-like local runs and smoke tests possible without an SMTP server or Mailpit, and it is allowed in every environment because nothing leaves the process.
func (*Log) SendMarketing ¶
func (sender *Log) SendMarketing( ctx context.Context, payload MarketingPayload, ) error
func (*Log) SendTransactional ¶
func (sender *Log) SendTransactional( ctx context.Context, payload TransactionalPayload, ) error
type Mailpit ¶
type Mailpit struct {
// contains filtered or unexported fields
}
Mailpit sends email through a development Mailpit SMTP server.
func NewMailpit ¶
func NewMailpit(config MailpitConfig) (*Mailpit, error)
NewMailpit constructs a Mailpit client from the supplied configuration.
func (*Mailpit) SendMarketing ¶
func (client *Mailpit) SendMarketing( ctx context.Context, payload MarketingPayload, ) error
func (*Mailpit) SendTransactional ¶
func (client *Mailpit) SendTransactional( ctx context.Context, payload TransactionalPayload, ) error
type MailpitConfig ¶
MailpitConfig configures a Mailpit SMTP client. Applications supply host and port.
func (MailpitConfig) Validate ¶
func (config MailpitConfig) Validate() error
Validate verifies Mailpit configuration.
type MarketingData ¶
type MarketingPayload ¶
type MarketingSender ¶
type MarketingSender interface {
SendMarketing(ctx context.Context, payload MarketingPayload) error
}
type PermanentError ¶
type PermanentError struct {
Err error
}
func (PermanentError) Error ¶
func (err PermanentError) Error() string
func (PermanentError) Unwrap ¶
func (err PermanentError) Unwrap() error
type SMTP ¶
type SMTP struct {
// contains filtered or unexported fields
}
SMTP sends email through a production SMTP relay.
func NewSMTP ¶
func NewSMTP(config SMTPConfig) (*SMTP, error)
NewSMTP constructs an SMTP sender from the supplied configuration.
func (*SMTP) SendMarketing ¶
func (sender *SMTP) SendMarketing( ctx context.Context, payload MarketingPayload, ) error
func (*SMTP) SendTransactional ¶
func (sender *SMTP) SendTransactional( ctx context.Context, payload TransactionalPayload, ) error
type SMTPConfig ¶
type SMTPConfig struct {
Host string
Port string
Username string
Password string
TLS SMTPTLSMode
Timeout time.Duration
}
SMTPConfig configures a production SMTP relay.
func (SMTPConfig) Validate ¶
func (config SMTPConfig) Validate() error
Validate verifies SMTP configuration. Username and password must be supplied together, and plaintext authentication is refused outside a local relay.
type SMTPTLSMode ¶
type SMTPTLSMode string
SMTPTLSMode selects how an SMTP connection is encrypted.
const ( // SMTPTLSStartTLS upgrades a plaintext connection with STARTTLS. It is the // default and the right choice for submission on port 587. SMTPTLSStartTLS SMTPTLSMode = "starttls" // SMTPTLSImplicit dials TLS directly, as submission on port 465 expects. SMTPTLSImplicit SMTPTLSMode = "tls" // SMTPTLSNone sends plaintext. Only use it for a local relay. SMTPTLSNone SMTPTLSMode = "none" )
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates renders the html/text template pairs exported by React Email. Uses text/template on purpose: html/template strips the <!--[if mso]> comments React Email emits for Outlook; HTML placeholders carry an explicit `| html` pipe.
func MustParseTemplates ¶
MustParseTemplates is ParseTemplates that panics on error. It is for templates committed to the binary with //go:embed, where a parse failure is a build-time bug.
func ParseTemplates ¶
ParseTemplates parses dir/*.html.tmpl and dir/*.txt.tmpl from fsys. Both template kinds are required: an email without an HTML or a text body is a scaffold mistake, not a render-time surprise.
type TemporaryError ¶
type TemporaryError struct {
Err error
}
func (TemporaryError) Error ¶
func (err TemporaryError) Error() string
func (TemporaryError) Unwrap ¶
func (err TemporaryError) Unwrap() error
type TransactionalData ¶
type TransactionalData struct {
To string
Cc []string
Bcc []string
From string
ReplyTo string
Subject string
HTMLBody string
TextBody string
Attachments []Attachment
Metadata map[string]string
}
func Compose ¶
func Compose(t Transformer, to, from, subject string) (TransactionalData, error)
Compose renders t into transactional data addressed to a single recipient.
type TransactionalPayload ¶
type TransactionalSender ¶
type TransactionalSender interface {
SendTransactional(ctx context.Context, payload TransactionalPayload) error
}
type Transformer ¶
Transformer renders an email template to both of its bodies.
type ValidationError ¶
type ValidationError struct {
Err error
}
func (ValidationError) Error ¶
func (err ValidationError) Error() string
func (ValidationError) Unwrap ¶
func (err ValidationError) Unwrap() error