mail

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(m *Message) error

Send is a shortcut for Default.Send (if Default is set).

Types

type Attachment

type Attachment struct {
	Filename string
	Data     []byte
	MIMEType string // e.g. "application/pdf". Auto-detected if empty.
}

Attachment represents a file attachment on an email.

type Driver

type Driver interface {
	Send(m *Message) error
}

Driver sends emails.

var Default Driver

Default driver (set by app).

type MailgunAPIDriver

type MailgunAPIDriver struct {
	Domain   string
	APIKey   string
	FromAddr string
	Endpoint string // defaults to "https://api.mailgun.net/v3"
	Client   *http.Client
}

MailgunAPIDriver sends email via the Mailgun HTTP API. This is a native API driver — no SMTP connection required.

driver := mail.NewMailgunAPIDriver("your-domain.com", "key-xxx", "sender@your-domain.com")
mail.Default = driver

func NewMailgunAPIDriver

func NewMailgunAPIDriver(domain, apiKey, fromAddr string) *MailgunAPIDriver

NewMailgunAPIDriver creates a Mailgun API driver.

func (*MailgunAPIDriver) Send

func (d *MailgunAPIDriver) Send(m *Message) error

Send sends the message via Mailgun's API.

type MailgunSMTPDriver

type MailgunSMTPDriver struct {
	// contains filtered or unexported fields
}

MailgunSMTPDriver wraps SMTPDriver for Mailgun SMTP transport. For the native API driver, use MailgunAPIDriver instead. Example addr: "smtp.mailgun.org:587".

func NewMailgunSMTPDriver

func NewMailgunSMTPDriver(addr string, auth smtp.Auth, fromAddr string) *MailgunSMTPDriver

func (*MailgunSMTPDriver) Send

func (d *MailgunSMTPDriver) Send(m *Message) error

type Message

type Message struct {
	From        string
	To          []string
	Cc          []string
	Bcc         []string
	ReplyTo     string
	Subject     string
	Body        string
	HTML        bool
	Attachments []Attachment
}

Message represents an email (plan: mail drivers SMTP, etc.).

func NewMessage

func NewMessage(subject string) *Message

NewMessage creates a new Message with the given subject.

func (*Message) AddBcc

func (m *Message) AddBcc(bcc ...string) *Message

AddBcc adds BCC recipients.

func (*Message) AddCc

func (m *Message) AddCc(cc ...string) *Message

AddCc adds CC recipients.

func (*Message) AllRecipients

func (m *Message) AllRecipients() []string

AllRecipients returns To + Cc + Bcc for envelope delivery.

func (*Message) Attach

func (m *Message) Attach(filename string, data []byte, mimeType ...string) *Message

Attach adds a file attachment.

func (*Message) SetBody

func (m *Message) SetBody(body string, html bool) *Message

SetBody sets the email body. Set html=true for HTML content.

func (*Message) SetFrom

func (m *Message) SetFrom(from string) *Message

SetFrom sets the sender address.

func (*Message) SetReplyTo

func (m *Message) SetReplyTo(replyTo string) *Message

SetReplyTo sets the reply-to address.

func (*Message) SetTo

func (m *Message) SetTo(to ...string) *Message

SetTo sets the primary recipients.

type PostmarkDriver

type PostmarkDriver struct {
	// contains filtered or unexported fields
}

PostmarkDriver wraps SMTPDriver for Postmark. Example addr: "smtp.postmarkapp.com:587".

func NewPostmarkDriver

func NewPostmarkDriver(addr string, auth smtp.Auth, fromAddr string) *PostmarkDriver

func (*PostmarkDriver) Send

func (d *PostmarkDriver) Send(m *Message) error

type ResendDriver

type ResendDriver struct {
	APIKey   string
	FromAddr string
	Endpoint string
	Client   *http.Client
}

ResendDriver sends email via the Resend HTTP API.

driver := mail.NewResendDriver("re_xxxx", "sender@example.com")
mail.Default = driver

func NewResendDriver

func NewResendDriver(apiKey, fromAddr string) *ResendDriver

NewResendDriver creates a Resend API driver.

func (*ResendDriver) Send

func (d *ResendDriver) Send(m *Message) error

Send sends the message via Resend's API.

type SESAPIDriver

type SESAPIDriver struct {
	Region    string
	AccessKey string
	SecretKey string
	FromAddr  string
	Client    *http.Client
}

SESAPIDriver sends email via the Amazon SES v2 HTTP API using AWS Signature Version 4. For simplicity, this driver uses the SES SendEmail Action via query parameters (no external AWS SDK required).

driver := mail.NewSESAPIDriver("us-east-1", "AKID...", "secret...", "sender@example.com")
mail.Default = driver

func NewSESAPIDriver

func NewSESAPIDriver(region, accessKey, secretKey, fromAddr string) *SESAPIDriver

NewSESAPIDriver creates an SES API driver (no SDK required).

func (*SESAPIDriver) Send

func (d *SESAPIDriver) Send(m *Message) error

Send sends the message via SES API. It builds a raw MIME message and sends it via the SES SendRawEmail action.

type SESDriver

type SESDriver struct {
	// contains filtered or unexported fields
}

SESDriver is a thin wrapper around SMTPDriver configured for Amazon SES SMTP. Use the SMTP credentials from your SES console.

func NewSESDriver

func NewSESDriver(addr string, auth smtp.Auth, fromAddr string) *SESDriver

NewSESDriver creates an SES driver. Example addr: "email-smtp.us-east-1.amazonaws.com:587".

func (*SESDriver) Send

func (d *SESDriver) Send(m *Message) error

type SMTPDriver

type SMTPDriver struct {
	Addr     string
	Auth     smtp.Auth
	FromAddr string
}

SMTPDriver sends via SMTP.

func NewSMTPDriver

func NewSMTPDriver(addr string, auth smtp.Auth, fromAddr string) *SMTPDriver

NewSMTPDriver returns an SMTP driver. auth can be nil for no auth.

func (*SMTPDriver) Send

func (d *SMTPDriver) Send(m *Message) error

Send sends the message via SMTP.

type SendGridDriver

type SendGridDriver struct {
	APIKey   string
	FromAddr string
	FromName string
	Endpoint string // defaults to "https://api.sendgrid.com/v3/mail/send"
	Client   *http.Client
}

SendGridDriver sends email via the SendGrid v3 HTTP API. This is a native API driver — no SMTP connection required.

driver := mail.NewSendGridDriver("SG.your-api-key", "sender@example.com")
mail.Default = driver

func NewSendGridDriver

func NewSendGridDriver(apiKey, fromAddr string) *SendGridDriver

NewSendGridDriver creates a SendGrid API driver.

func (*SendGridDriver) Send

func (d *SendGridDriver) Send(m *Message) error

Send sends the message via SendGrid's v3 API.

type SendGridSMTPDriver

type SendGridSMTPDriver struct {
	// contains filtered or unexported fields
}

SendGridSMTPDriver wraps SMTPDriver for SendGrid SMTP transport. For the native API driver, use SendGridDriver instead. Example addr: "smtp.sendgrid.net:587".

func NewSendGridSMTPDriver

func NewSendGridSMTPDriver(addr string, auth smtp.Auth, fromAddr string) *SendGridSMTPDriver

func (*SendGridSMTPDriver) Send

func (d *SendGridSMTPDriver) Send(m *Message) error

Jump to

Keyboard shortcuts

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