email

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 10 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

func InitDefault added in v0.2.6

func InitDefault(cfg Config) error

InitDefault creates the package-level default sender from cfg. A later successful call replaces the previous default.

func IsEmail

func IsEmail(input string) bool

IsEmail reports whether input is a syntactically valid e-mail address according to a standard RFC 5321/5322 compatible regular expression.

Types

type Config added in v0.2.6

type Config struct {
	Host        string // SMTP server host name
	Port        int    // 465 = implicit TLS; any other port must offer STARTTLS
	Username    string // SMTP login
	Password    string // SMTP password
	FromAddress string // sender address used when Message.From is empty
	FromName    string // optional display name of FromAddress
}

Config is the SMTP server and the default sender. email/component reads it from the email section of app.toml.

func (Config) Validate added in v0.2.6

func (c Config) Validate() error

Validate checks that the server, the login and the sender are set and well formed.

type Message added in v0.2.6

type Message struct {
	From        []string `json:"from,omitempty" validate:"omitempty,min=1,max=2"`          // [0] sender address, [1] optional display name; empty = the sender of Config
	To          []string `json:"to,omitempty" validate:"required,min=1,dive,email"`        // primary recipient addresses
	Cc          []string `json:"cc,omitempty" validate:"omitempty,dive,email"`             // carbon-copy recipient addresses
	Bcc         []string `json:"bcc,omitempty" validate:"omitempty,dive,email"`            // blind carbon-copy recipient addresses
	Subject     string   `json:"subject,omitempty" validate:"omitempty,min=0,max=500"`     // subject line
	Body        string   `json:"body,omitempty"`                                           // body text
	ContentType string   `json:"contentType,omitempty" validate:"omitempty,min=0,max=100"` // text/plain or text/html (default); parameters such as charset are ignored
}

Message is an outbound email: sender, recipients and content. Attachments are not supported. The validate tags are for validator.Validator() when the message comes from a request body.

type SMTPSender added in v0.2.6

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

SMTPSender sends email through one SMTP server with github.com/wneessen/go-mail. It is safe for concurrent use.

func Default added in v0.2.6

func Default() *SMTPSender

Default returns the package-level default sender, or nil before InitDefault succeeds. Use NewSMTPSender for any other instance.

func NewSMTPSender added in v0.2.6

func NewSMTPSender(cfg Config) (*SMTPSender, error)

NewSMTPSender checks cfg and returns a sender for it. It does not connect: each Send opens its own connection.

func (*SMTPSender) Send added in v0.2.6

func (s *SMTPSender) Send(msg *Message) error

Send checks msg, builds the MIME message and sends it. An empty msg.From means the sender of the Config.

type Sender added in v0.2.6

type Sender interface {
	Send(msg *Message) error
}

Sender sends one email message.

Directories

Path Synopsis
Package component provides email sender lifecycle integration for bootstrap.
Package component provides email sender lifecycle integration for bootstrap.

Jump to

Keyboard shortcuts

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