mailgun

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mailgun provides a Mailgun provider adapter for the goemail library.

It implements the email.Sender interface using the Mailgun v3 Messages API, allowing you to send emails through Mailgun without pulling in any external SDK dependencies.

Usage

sender, err := mailgun.New(mailgun.Config{
    Domain: "mg.example.com",
    APIKey: os.Getenv("MAILGUN_API_KEY"),
})
if err != nil {
    log.Fatal(err)
}
defer sender.Close()

e, _ := email.NewEmail().
    SetFrom("sender@mg.example.com").
    AddTo("recipient@example.com").
    SetSubject("Hello from Mailgun").
    SetBody("Plain text body").
    Build()

err = sender.Send(context.Background(), e)

EU Region

For EU-based Mailgun accounts, set the BaseURL:

sender, _ := mailgun.New(mailgun.Config{
    Domain:  "mg.example.com",
    APIKey:  os.Getenv("MAILGUN_API_KEY"),
    BaseURL: "https://api.eu.mailgun.net",
})

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 Mailgun sending domain (required, e.g., "mg.example.com").
	Domain string

	// APIKey is the Mailgun API key (required).
	APIKey string

	// BaseURL is the Mailgun API base URL.
	// Default: "https://api.mailgun.net".
	// For EU accounts use "https://api.eu.mailgun.net".
	BaseURL string

	// HTTPClient is the HTTP client used for API calls.
	// Default: http.DefaultClient.
	HTTPClient *http.Client
}

Config holds the Mailgun provider configuration.

type Sender

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

Sender sends emails through the Mailgun v3 Messages API.

func New

func New(cfg Config) (*Sender, error)

New creates a new Mailgun Sender.

func (*Sender) Close

func (s *Sender) Close() error

Close is a no-op for Mailgun (HTTP is stateless).

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, e *email.Email) error

Send sends an email through Mailgun. It implements email.Sender.

Jump to

Keyboard shortcuts

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