mailer

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: BSD-3-Clause Imports: 7 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

codecov GoDoc Go Report Card

Mailer

Package mailer is a functional wrapper around the standard "net/smtp" and "html/template" packages.

Documentation

Overview

Package mailer is a functional wrapper around the standard "net/smtp" and "html/template" packages.

Index

Constants

View Source
const (
	// GlobalHeaders is set on every message.
	GlobalHeaders = "MIME-Version: 1.0\r\nContent-type: text/html; charset=\"UTF-8\"\r\n\r\n"
)

Variables

View Source
var Debug bool

Debug mode prints the outgoing mail before sending

Functions

This section is empty.

Types

type Header struct {
	Key    string
	Values []string
}

Header for mail message

func (Header) String

func (h Header) String() string

type Mailer

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

Mailer holds a html template, server and authentication information for efficient reuse.

func New

func New(tmpl *template.Template, addr, from string, auth smtp.Auth) *Mailer

New returns a reusable mailer. Tmpl should hold a collection of parsed templates. Addr is the hostname and port used by smtp.SendMail. For example:

"mail.host.com:587"

From is used in every subsequent SendMail invocation and set as message header. If auth is nil, connections will omit authentication.

func (*Mailer) Send

func (m *Mailer) Send(headers []Header, tmplName string, data interface{}, recipients ...string) error

Send renders the headers and named template with passed data. The rendered message is sent using smtp.SendMail, to all the recipients.

Headers keys are rendered Title cased, and the values are joined with a comma separator. Each entry becomes a CRLF separated line. For example:

{"to", []string{"test@test.mailu.io", "admin@test.mailu.io"}}

Results in:

To: test@test.mailu.io,admin@test.mailu.io

The current time is automatically appended as timestamp header.

Jump to

Keyboard shortcuts

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