Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

mail

v1.1.1
djinn-ci.com/mail

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

9 matches

Top ↑

Package mail provides a simple SMTP client for sending plain-text emails.

Types

Client

type Client struct {
	*smtp.Client
	// contains filtered or unexported fields
}

NewClient

func NewClient(cfg ClientConfig) (*Client, error)

NewClient will use the given ClientConfig to return an *smtp.Client. Depending on the fields present in the given config will determine whether authentication or TLS connectivity is made.

ClientConfig

type ClientConfig struct {
	// CA is the path to the PEM encoded root CAs. If empty then TLS will not
	// be attempted upon connection to the SMTP server.
	CA string

	// Addr is the full address (host and port) of the SMTP server to connect
	// to.
	Addr string

	// Username and Password are the credentials to use the plain
	// authentication against the SMTP server. If none are provided then no
	// authentication attempts are made.
	Username string
	Password string
}

ClientConfig specifies how the client connection to the SMTP server should be configured.

ErrRcpts

type ErrRcpts map[string]string

ErrRcpts is a list of any errors that occur when a RCPT command is send to the SMTP server. This will store each error message against the corresponding recipient that caused the error.

ErrRcpts.Error

func (e *ErrRcpts) Error() string

Error returns a formatted string of the recipients that couldn't received the email alongside ther original error.

Mail

type Mail struct {
	From    string   // From is the address we're sending the mail from.
	To      []string // To is the list of addresses to send the mail to.
	Subject string   // Subject is the subject line of the mail.
	Body    string   // Body is the body of the mail.
}

Mail.Send

func (m Mail) Send(cli *Client) error

Send builds up the current Mail into something that can be sent to the given smtp.Client. If any errors occur when adding a recipient via RCPT, then an attempt to send the mail will still be done, and the ErrRcpts type will be returned.

Mail.String

func (m Mail) String() string

String returns the string representation of the current mail. This is typically what's written to the SMTP server once the DATA command has been issued.

Dependency graph