mailer

package module
v0.0.0-...-9c58ae4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 10 Imported by: 0

README

mailer

Golang package that generates clean, responsive HTML e-mails for sending mails.

This package is heavily inspired by mailgen and hermes.

Documentation

Overview

Package mailer is a helper package allowing you to easily generate and send mails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Instructions string
	Button       Button
	InviteCode   string
}

Action is anything the user can act on (i.e., click on a button, view an invite code)

type Body

type Body struct {
	Name         string   // The name of the contacted person
	Intros       []string // Intro sentences, first displayed in the email
	Dictionary   []Entry  // A list of key+value (useful for displaying parameters/settings/personal info)
	Table        Table    // Table is an table where you can put data (pricing grid, a bill, and so on)
	Actions      []Action // Actions are a list of actions that the user will be able to execute via a button click
	Outros       []string // Outro sentences, last displayed in the email
	Greeting     string   // Greeting for the contacted person (default to 'Hi')
	Signature    string   // Signature for the contacted person (default to 'Yours truly')
	Title        string   // Title replaces the greeting+name when set
	FreeMarkdown Markdown // Free markdown content that replaces all content other than header and footer
}

Body is the body of the email, containing all interesting data

type Button

type Button struct {
	Color     string
	TextColor string
	Text      string
	Link      string
}

Button defines an action to launch

type Columns

type Columns struct {
	CustomWidth     map[string]string
	CustomAlignment map[string]string
}

Columns contains meta-data for the different columns

type Default

type Default struct{}

Default is the theme by default

func (*Default) HTMLTemplate

func (dt *Default) HTMLTemplate() string

HTMLTemplate returns a Golang template that will generate an HTML email.

func (*Default) Name

func (dt *Default) Name() string

Name returns the name of the default theme

func (*Default) PlainTextTemplate

func (dt *Default) PlainTextTemplate() string

PlainTextTemplate returns a Golang template that will generate an plain text email.

type Email

type Email struct {
	Body Body
}

Email is the email containing a body

type Entry

type Entry struct {
	Key   string
	Value string
}

Entry is a simple entry of a map Allows using a slice of entries instead of a map Because Golang maps are not ordered

type Flat

type Flat struct{}

Flat is a theme

func (*Flat) HTMLTemplate

func (dt *Flat) HTMLTemplate() string

HTMLTemplate returns a Golang template that will generate an HTML email.

func (*Flat) Name

func (dt *Flat) Name() string

Name returns the name of the flat theme

func (*Flat) PlainTextTemplate

func (dt *Flat) PlainTextTemplate() string

PlainTextTemplate returns a Golang template that will generate an plain text email.

type Mailer

type Mailer struct {
	Theme              Theme
	TextDirection      TextDirection
	Product            Product
	DisableCSSInlining bool
}

Mailer represents a mailer instance.

func (*Mailer) GenerateHTML

func (h *Mailer) GenerateHTML(email Email) (string, error)

GenerateHTML generates the email body from data to an HTML Reader This is for modern email clients

func (*Mailer) GeneratePlainText

func (h *Mailer) GeneratePlainText(email Email) (string, error)

GeneratePlainText generates the email body from data This is for old email clients

type Markdown

type Markdown template.HTML

Markdown is a HTML template (a string) representing Markdown content https://en.wikipedia.org/wiki/Markdown

func (Markdown) ToHTML

func (c Markdown) ToHTML() template.HTML

ToHTML converts Markdown to HTML

type Product

type Product struct {
	Name        string
	Link        string // e.g. https://matcornic.github.io
	Copyright   string // Copyright © 2019 Hermes. All rights reserved.
	TroubleText string // TroubleText is the sentence at the end of the email for users having trouble with the button (default to `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.`)
}

Product represents your company product (brand) Appears in header & footer of e-mails

type Table

type Table struct {
	Data    [][]Entry // Contains data
	Columns Columns   // Contains meta-data for display purpose (width, alignement)
}

Table is an table where you can put data (pricing grid, a bill, and so on)

type Template

type Template struct {
	Mailer Mailer
	Email  Email
}

Template is the struct given to Golang templating Root object in a template is this struct

type TextDirection

type TextDirection string

TextDirection of the text in HTML email.

const TDLeftToRight TextDirection = "ltr"

TDLeftToRight is the text direction from left to right (default)

const TDRightToLeft TextDirection = "rtl"

TDRightToLeft is the text direction from right to left

type Theme

type Theme interface {
	// Name returns the name of the theme.
	Name() string

	// HTMLTemplate returns the raw GoLang template string for HTML mails.
	HTMLTemplate() string

	// PlainTextTemplate returns the raw GoLang template string for plain-text mails.
	PlainTextTemplate() string
}

Theme represents methods of a Theme.

Jump to

Keyboard shortcuts

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