mailing

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyRecipientList is returned when an empty recipient list is passed to the Sender.Send method.
	ErrEmptyRecipientList = errors.New("empty recipient list")
	// ErrEmptySender is returned when an empty sender email address is passed to the Sender.Send method.
	ErrEmptySender = errors.New("empty sender")
	// ErrInvalidSender is returned when an invalid email address is passed to the Sender.Send method.
	ErrInvalidSender = errors.New("invalid sender")
	// ErrInvalidRecipient is returned when an invalid email is passed in the list of recipients to the Sender.Send method.
	ErrInvalidRecipient = errors.New("invalid recipient")
	// ErrInvalidData is returned when an invalid data is passed to the Sender.Send method.
	ErrInvalidData = errors.New("invalid data")
)
View Source
var ErrTemplateNotFound = errors.New("template not found")

ErrTemplateNotFound is returned when a given template is not found inside the list of available templates.

Functions

This section is empty.

Types

type Sender

type Sender interface {
	// Send sends an email from sender to the given recipients. The email body is composed by an HTML template
	// that is filled in with values provided in data.
	Send(ctx context.Context, sender string, recipients, cc, bcc []string, subject, template string, data any) error
}

Sender allows sending emails through an email service.

func NewNopEmailSender

func NewNopEmailSender() Sender

NewNopEmailSender returns a no-op Sender. It never interacts with an email service provider. This Sender implementation is useful when a service doesn't want to enable sending emails.

func NewSendgridDynamicTemplatesEmailSender

func NewSendgridDynamicTemplatesEmailSender(client sendgridSender) Sender

NewSendgridDynamicTemplatesEmailSender initializes a new Sender with a sendgrid client. It will send emails through sendgrid using dynamic templates defined in the Sendgrid dashboard.

func NewSendgridEmailSender

func NewSendgridEmailSender(client sendgridSender) Sender

NewSendgridEmailSender initializes a new Sender with a sendgrid client. It will send emails using Go templates. See NewTemplateSender for conveniently handling Go templates in your project.

func NewSimpleEmailServiceSender

func NewSimpleEmailServiceSender(api sesiface.SESAPI) Sender

NewSimpleEmailServiceSender returns a Sender implementation using AWS Simple Email Service.

func NewTemplateSender

func NewTemplateSender(sender Sender, templates map[string]string) Sender

NewTemplateSender initializes a new Sender implementation that sends pre-defined templates using another email sender. Emails are sent by specifying the template to use and providing data for them.

The sender argument contains a Sender implementation. This is what is actually used to send emails.

The templates argument maps template identifiers to template filepaths. The identifiers are used to select the template to send.

Example:
sender := NewSendgridEmailSender(..)
sender = NewTemplateSender(sender, map[string]string{ "event.users.signup": "./templates/users/signup.gohtml", })

Jump to

Keyboard shortcuts

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