email

package
v1.20220411.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package email includes helpers for sending SMTP messages.

Index

Constants

View Source
const (
	ErrMessageFieldUnset    ex.Class = "email; message required field unset"
	ErrMessageFieldNewlines ex.Class = "email; message field contains newlines"
)

Errors

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	From     string   `json:"from" yaml:"from"`
	To       []string `json:"to" yaml:"to"`
	CC       []string `json:"cc" yaml:"cc"`
	BCC      []string `json:"bcc" yaml:"bcc"`
	Subject  string   `json:"subject" yaml:"subject"`
	TextBody string   `json:"textBody" yaml:"textBody"`
	HTMLBody string   `json:"htmlBody" yaml:"htmlBody"`
}

Message is a message to send via. ses.

func ApplyMessageOptions

func ApplyMessageOptions(m Message, options ...MessageOption) Message

ApplyMessageOptions applies options to a message and returns the mutated copy.

func MergeMessages

func MergeMessages(messages ...Message) (output Message)

MergeMessages merges a given set of messages, such that messages that appear last override the options in the output message provided those fields are set.

If message A has just the `To` field set, and message B has just the `Subject`field set, and message C also has the `To` field set, the result of:

MergeMessages(a,b,c)

Will be `To` of C, and `Subject` of B, with C overwriting the `To` of A.

func (Message) IsZero

func (m Message) IsZero() bool

IsZero returns if the object is set or not.

func (Message) Validate

func (m Message) Validate() error

Validate checks that a message can be sent.

type MessageOption

type MessageOption func(m *Message)

MessageOption is a mutator for messages.

func OptBCC

func OptBCC(bcc ...string) MessageOption

OptBCC sets the bcc addresses for a message.

func OptCC

func OptCC(cc ...string) MessageOption

OptCC sets the cc addresses for a message.

func OptFrom

func OptFrom(from string) MessageOption

OptFrom sets the from address for a message.

func OptHTMLBody

func OptHTMLBody(htmlBody string) MessageOption

OptHTMLBody sets the html body for a message.

func OptSubject

func OptSubject(subject string) MessageOption

OptSubject sets the subject for a message.

func OptTextBody

func OptTextBody(textBody string) MessageOption

OptTextBody sets the text body for a message.

func OptTo

func OptTo(to ...string) MessageOption

OptTo sets the to address for a message.

type MockSender

type MockSender chan Message

MockSender is a mocked sender.

func NewMockSender

func NewMockSender() MockSender

NewMockSender creates a new mock sender.

func (MockSender) Send

func (ms MockSender) Send(ctx context.Context, m Message) error

Send sends a mocked message.

type SMTPPlainAuth

type SMTPPlainAuth struct {
	Identity string `json:"identity" yaml:"identity"`
	Username string `json:"username" yaml:"username" env:"SMTP_USERNAME"`
	Password string `json:"password" yaml:"password" env:"SMTP_PASSWORD"`
}

SMTPPlainAuth is a auth set for smtp.

func (SMTPPlainAuth) IsZero

func (spa SMTPPlainAuth) IsZero() bool

IsZero returns if the plain auth is unset.

func (SMTPPlainAuth) Resolve

func (spa SMTPPlainAuth) Resolve(ctx context.Context) error

Resolve implements configutil.ConfigResolver.

type SMTPSender

type SMTPSender struct {
	LocalName string        `json:"localname" yaml:"localname"`
	Host      string        `json:"host" yaml:"host" env:"SMTP_HOST"`
	Port      string        `json:"port" yaml:"port" env:"SMTP_PORT"`
	PlainAuth SMTPPlainAuth `json:"plainAuth" yaml:"plainAuth"`
}

SMTPSender is a sender for emails over smtp.

func (SMTPSender) IsZero

func (s SMTPSender) IsZero() bool

IsZero returns if the smtp sender is set or not.

func (SMTPSender) LocalNameOrDefault

func (s SMTPSender) LocalNameOrDefault() string

LocalNameOrDefault returns a property or a default.

func (SMTPSender) PortOrDefault

func (s SMTPSender) PortOrDefault() string

PortOrDefault returns a property or a default.

func (*SMTPSender) Resolve

func (s *SMTPSender) Resolve(ctx context.Context) error

Resolve implements configutil.ConfigResolver.

func (SMTPSender) Send

func (s SMTPSender) Send(ctx context.Context, message Message) error

Send sends an email via. smtp.

type Sender

type Sender interface {
	Send(context.Context, Message) error
}

Sender is a generalized sender.

Jump to

Keyboard shortcuts

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