email

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package email provides a Mailgun-backed email sender for transactional email delivery. It is intentionally dependency-free beyond the Go standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	Data        []byte
	Inline      bool
}

Attachment describes a file to attach to an email. Data is raw file bytes.

type EmailMessage

type EmailMessage struct {
	From        string
	To          []string
	CC          []string
	BCC         []string
	Subject     string
	Text        string
	HTML        string
	Attachments []Attachment
}

EmailMessage represents an email to be sent.

type MailgunClient

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

MailgunClient sends emails via the Mailgun API.

func NewMailgunClient

func NewMailgunClient(cfg MailgunConfig) *MailgunClient

NewMailgunClient creates a MailgunClient from a MailgunConfig. The returned client uses a dedicated http.Client with a 30-second timeout and connection pooling.

func (*MailgunClient) Send

func (c *MailgunClient) Send(ctx context.Context, msg *EmailMessage) (string, error)

Send posts the email to Mailgun.

type MailgunConfig added in v0.3.2

type MailgunConfig struct {
	Endpoint string `env:"ENDPOINT"`
	User     string `env:"USER"`
	Password string `env:"PASSWORD"`
	From     string `env:"FROM" envDefault:"noti@doublefin.com"`
}

MailgunConfig holds the configuration for a MailgunClient.

The struct tags follow the caarlos0/env convention so that consumers using that library can parse environment variables with a "MAILGUN_" prefix (e.g. MAILGUN_ENDPOINT, MAILGUN_PASSWORD). The tags themselves do not trigger automatic env-var reading; the caller is responsible for parsing.

func (MailgunConfig) LogValue added in v0.3.2

func (c MailgunConfig) LogValue() slog.Value

LogValue implements slog.LogValuer, redacting the password.

type Sender

type Sender interface {
	Send(ctx context.Context, msg *EmailMessage) (string, error)
}

Sender is the interface satisfied by MailgunClient. It enables mock injection in tests and decouples callers from the concrete implementation.

Jump to

Keyboard shortcuts

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