v1.1.1 Latest Latest

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 0



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



This section is empty.


This section is empty.


This section is empty.


type Client

type Client struct {
	// contains filtered or unexported fields

func 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.

type 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.

type 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.

func (*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.

type 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.

func (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.

func (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.

Jump to

Keyboard shortcuts

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