mailer

package module
v0.0.0-...-2dacc9d Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 8 Imported by: 0

README

= mailer

Mailer defines interfaces for sending and fetching e-mail.

It also implements a template engine and some line-ending transformations to simplify generating messages.

== Acknowledgments

The templates code is derived from a
https://gist.github.com/logrusorgru/abd846adb521a6fb39c7405f32fec0cf[gist]
by Konstanin Ivanov (link:mailto:[kostyarin.ivanov@gmail.com]).

Documentation

Overview

Package mailer defines interfaces to send and fetch messages. It also provides a simple template engine and transformers to "fix up" line endings for message bodies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrLfToLf

func CrLfToLf(b []byte) []byte

CrLfToLf transforms all CR+LF endings to LF.

func CrToLf

func CrToLf(b []byte) []byte

CrToLf transforms all CR endings to LF.

Types

type Attachment

type Attachment struct {
	Name string
	Data []byte
}

Attachment implements e-mail attachments.

type Envelope

type Envelope struct {
	Sender  mail.Address
	To      []mail.Address
	Cc      []mail.Address
	Bcc     []mail.Address
	Subject string
}

Envelope specifies the e-mail envelope information.

type Fetcher

type Fetcher interface {
	Get() error
	Errors() []error
}

Fetcher is the interface for retrieving e-mails from the server and storing them as files in the mailbox directory.

type Sender

type Sender interface {
	Send(e *Envelope, t *Template, name string, data interface{}, attachments ...*Attachment) []error
	SendHTML(e *Envelope, t *Template, name string, data interface{}, attachments ...*Attachment) []error
	Errors() []error
}

Sender is the interface for generating e-mails and connecting to the server to send them.

type Template

type Template struct {
	*template.Template // root template
	// contains filtered or unexported fields
}

Template implements a template engine largely copied from https://gist.github.com/logrusorgru/abd846adb521a6fb39c7405f32fec0cf

func NewTemplate

func NewTemplate(dir, ext string, funcMap template.FuncMap) (t *Template, err error)

NewTemplate creates a new Template and performs the initial load of all template files that are in the template path. The dir argument is the directory to load templates from. The ext argument is extension of template files. It must include the leading dot. For example, ".gohtml," not "gohtml."

func (*Template) Dir

func (t *Template) Dir() string

Dir returns absolute path to directory with views

func (*Template) Ext

func (t *Template) Ext() string

Ext returns extension of views

func (*Template) Load

func (t *Template) Load() (err error)

Load all templates by walking the template path, finding all files that match the template extension, and loading each of them.

func (*Template) Render

func (t *Template) Render(w io.Writer, name string, data interface{}) error

Render the template using the data provided.

Jump to

Keyboard shortcuts

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