email

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename string // Filename to display for the attachment.
	Data     []byte // Raw file data.
}

Attachment represents a single email attachment.

type Client

type Client interface {
	Mail(from string) error
	Rcpt(to string) error
	Data() (io.WriteCloser, error)
	Close() error
	StartTLS(config *tls.Config) error
	Auth(auth smtp.Auth) error
}

Client represents a low-level connection to an SMTP server.

type ContextDialer added in v0.21.0

type ContextDialer interface {
	DialContext(ctx context.Context, addr string) (Client, error)
}

ContextDialer establishes SMTP connections with a context.

type DefaultDialer

type DefaultDialer struct{}

DefaultDialer implements Dialer using the standard net/smtp package.

func (DefaultDialer) Dial

func (DefaultDialer) Dial(addr string) (Client, error)

Dial connects to the SMTP server using the standard library's smtp.Dial.

Parameters:

  • addr: SMTP server address in host:port format.

Returns:

  • Client: An active SMTP connection.
  • error: If the connection fails.

func (DefaultDialer) DialContext added in v0.21.0

func (DefaultDialer) DialContext(ctx context.Context, addr string) (Client, error)

DialContext connects to the SMTP server with a context.

type Dialer

type Dialer interface {
	// Dial connects to the SMTP server at the specified address.
	//
	// Parameters:
	//   - addr: The address of the SMTP server (e.g. "smtp.example.com:587").
	//
	// Returns:
	//   - Client: An established SMTP client.
	//   - error: If the connection cannot be established.
	Dial(addr string) (Client, error)
}

Dialer establishes SMTP connections for sending messages.

type MailClient

type MailClient struct {
	SMTPConfig SMTPConfig // SMTPConfig holds connection and authentication settings.
	Dialer     Dialer     // Dialer provides SMTP connections.
}

MailClient sends email messages using SMTP.

func New

func New(cfg SMTPConfig) *MailClient

New returns a new MailClient with the given SMTP settings.

Parameters:

  • cfg: The SMTPConfig specifying connection and authentication details.

Returns:

  • *MailClient: A configured MailClient ready to send messages.

func (*MailClient) Send

func (c *MailClient) Send(ctx context.Context, msg Message) error

Send sends the given email message using the configured SMTP settings.

Parameters:

  • ctx: A context to manage cancellation and timeout.
  • msg: The email Message to send.

Returns:

  • error: If sending the message fails at any stage.

type Message

type Message struct {
	To          []string     `yaml:"to,omitempty"`          // Recipient email addresses.
	Cc          []string     `yaml:"cc,omitempty"`          // CC recipient email addresses.
	Bcc         []string     `yaml:"bcc,omitempty"`         // BCC recipient email addresses.
	IsHTML      bool         `yaml:"is_html,omitempty"`     // Whether the body is HTML formatted.
	Subject     string       `yaml:"subject,omitempty"`     // Subject of the email.
	Body        string       `yaml:"body,omitempty"`        // Body content of the email.
	Attachments []Attachment `yaml:"attachments,omitempty"` // Optional file attachments.
}

Message represents an email to be sent.

type SMTPConfig

type SMTPConfig struct {
	Host               string `yaml:"host,omitempty"`                 // SMTP server hostname.
	Port               int    `yaml:"port,omitempty"`                 // SMTP server port.
	From               string `yaml:"from,omitempty"`                 // Sender email address.
	Username           string `yaml:"username,omitempty"`             // SMTP username.
	Password           string `yaml:"password,omitempty"`             // SMTP password.
	StartTLS           *bool  `yaml:"start_tls,omitempty"`            // Whether to initiate STARTTLS.
	SkipInsecureVerify *bool  `yaml:"skip_insecure_verify,omitempty"` // Whether to skip TLS certificate verification.
}

SMTPConfig contains connection and authentication settings for an SMTP server.

type Sender

type Sender interface {
	// Send sends the given message using the SMTP protocol.
	//
	// Parameters:
	//   - ctx: The context used to control timeout or cancellation.
	//   - msg: The Message to be sent.
	//
	// Returns:
	//   - error: If sending the message fails.
	Send(ctx context.Context, msg Message) error
}

Sender defines an interface for sending email messages.

Jump to

Keyboard shortcuts

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