mail

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mail sends SMTP mail. It is the one notification channel that is not a webhook, and the only one that can carry an attachment.

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
	Content     []byte
}

Attachment is a file carried by a message. SMTP is the only channel that accepts one.

type Auth

type Auth string

Auth selects how the SMTP session authenticates.

const (
	AuthNone   Auth = "None"
	AuthPlain  Auth = "Plain"
	AuthOAuth2 Auth = "OAuth2"
)

type Encryption

type Encryption string

Encryption selects how the SMTP connection is secured.

const (
	// EncryptionAuto upgrades with STARTTLS, the same as explicit TLS.
	EncryptionAuto Encryption = "Auto"
	// EncryptionNone sends in the clear.
	EncryptionNone Encryption = "None"
	// EncryptionExplicitTLS connects in the clear then issues STARTTLS.
	EncryptionExplicitTLS Encryption = "ExplicitTLS"
	// EncryptionImplicitTLS connects with TLS from the first byte.
	EncryptionImplicitTLS Encryption = "ImplicitTLS"
)

type Mail

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

Mail is one message under construction.

func New

func New(to []string, subject, body, contentType string) *Mail

New starts a message. contentType is the body's, e.g. `text/html; charset="UTF-8"`.

func (*Mail) AddAttachment

func (m *Mail) AddAttachment(attachment Attachment) *Mail

func (*Mail) Send

func (m *Mail) Send(conn SMTPConnection) error

Send delivers the message over conn.

func (*Mail) SetCredentials

func (m *Mail) SetCredentials(host string, port int, user, password string) *Mail

func (*Mail) SetFrom

func (m *Mail) SetFrom(name, email string) *Mail

func (*Mail) SetHeader

func (m *Mail) SetHeader(key, value string) *Mail

type SMTPConnection

type SMTPConnection struct {
	Host        string       `json:"host,omitempty" yaml:"host,omitempty"`
	Port        int          `json:"port,omitempty" yaml:"port,omitempty"`
	Username    types.EnvVar `json:"username,omitempty" yaml:"username,omitempty"`
	Password    types.EnvVar `json:"password,omitempty" yaml:"password,omitempty"`
	FromAddress string       `json:"fromAddress,omitempty" yaml:"fromAddress,omitempty"`
	FromName    string       `json:"fromName,omitempty" yaml:"fromName,omitempty"`
	Encryption  Encryption   `json:"encryption,omitempty" yaml:"encryption,omitempty"`
	Auth        Auth         `json:"auth,omitempty" yaml:"auth,omitempty"`
	InsecureTLS bool         `json:"insecureTLS,omitempty" yaml:"insecureTLS,omitempty"`

	// To is the default recipient list, used when a message names none.
	To []string `json:"to,omitempty" yaml:"to,omitempty"`
}

SMTPConnection is a mail server. It is derived from a models.Connection of type email, or parsed from an smtp:// URL.

func FromConnection

func FromConnection(conn *models.Connection) (SMTPConnection, error)

FromConnection projects a stored connection onto an SMTP connection. The connection must already be hydrated: this reads resolved values, it does not resolve secrets itself.

func FromURL

func FromURL(raw string) (SMTPConnection, error)

FromURL parses an smtp:// URL, including the query parameters the shoutrrr URL form used, so URLs already written against the old form keep working.

Jump to

Keyboard shortcuts

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