Help us shape the future of Go! Take the 2026 Go Developer Survey

mailgun

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mailgun implements mail.Mailer against Mailgun's HTTP API (https://documentation.mailgun.com/en/latest/api-sending.html).

Compared to the SMTP transport, the HTTP driver is friendlier to platforms that block outbound port 25/465/587 (Heroku, App Engine, Cloud Run, certain corporate networks) and gives Mailgun-specific affordances like tags, custom variables, and SMTP-suppression- list bypass via `v:`-headers.

Usage:

m := mailgun.New(mailgun.Config{
    Domain: "mg.example.com",
    APIKey: os.Getenv("MAILGUN_KEY"),
    From:   "noreply@example.com",
})
err := m.Send(ctx, mail.NewMessage().
    To("user@example.com").
    Subject("Hi").
    HTML("<b>hello</b>").
    Build())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Domain is the sending domain registered with Mailgun
	// (e.g. "mg.example.com").
	Domain string
	// APIKey is the private API key.
	APIKey string
	// From is the default From address used when Message.From is empty.
	From string
	// Region defaults to RegionUS when unset.
	Region Region
	// HTTPClient is the http.Client used for requests. Default has a
	// 30s timeout.
	HTTPClient *http.Client
}

Config holds the Mailgun API credentials.

type Mailer

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

Mailer talks the Mailgun HTTP API.

func New

func New(cfg Config) *Mailer

New constructs a Mailer.

func (*Mailer) Send

func (m *Mailer) Send(ctx context.Context, msg mail.Message) error

Send dispatches msg via Mailgun. Non-2xx responses surface the Mailgun error body in the returned error for easier debugging.

type Region

type Region string

Region selects the Mailgun region endpoint.

const (
	RegionUS Region = "https://api.mailgun.net/v3"
	RegionEU Region = "https://api.eu.mailgun.net/v3"
)

Jump to

Keyboard shortcuts

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