mail

package
v0.0.0-...-1535236 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterSentMailViewer

func RegisterSentMailViewer[T any](router *medium.Router[T], mailer *Mailer)

Types

type Deliverer

type Deliverer interface {
	SendMail(context.Context, *Message) error
}

Represents a type that can be used to send emails to mail servers.

type Mailer

type Mailer struct {
	DevMode bool

	From string

	// SentMessages is slice of mail that is collected when DevMode is true.
	SentMail []Message
	// contains filtered or unexported fields
}

Mailer stores state required to connect to a mail server and send emails. It requires a view.Renderer so that it can send HTML emails.

func New

func New(deliverer Deliverer, renderer *bat.Engine) *Mailer

Creates a new mailer, accepting a renderer which is used to render HTML emails, the mailer host, and the mailer auth.

func (*Mailer) NewMessage

func (m *Mailer) NewMessage(subject string, to ...string) *Message

Creates a new message that can be modified and delivered via Send

func (*Mailer) ResetSentMail

func (m *Mailer) ResetSentMail()

func (*Mailer) Send

func (m *Mailer) Send(ctx context.Context, msg *Message) error

Sends an email using the mailer's host and auth.

type Message

type Message struct {
	To      []string
	From    string
	Subject string
	SentAt  time.Time

	Body        string
	ContentType string
	Contents    []MessageBody
	// contains filtered or unexported fields
}

Message is used to store the data required to send an email.

func NewMail

func NewMail(to []string, subject string, from string, body string) *Message

Creates a new email message that can be sent.

func (*Message) Multipart

func (m *Message) Multipart(templates []string, data map[string]any) error

func (*Message) Send

func (m *Message) Send(ctx context.Context, deliverer Deliverer) error

Sends an email using the passed in deliverer.

func (*Message) Template

func (m *Message) Template(template string, data map[string]any) error

type MessageBody

type MessageBody struct {
	ContentType string
	Body        string
}

Jump to

Keyboard shortcuts

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