letter

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecipientsHeader

func RecipientsHeader(recipients []mail.Address) string

RecipientsHeader builds the mail header value for the given recipients.

Types

type AttachOption

type AttachOption func(*Attachment)

AttachOption is an attachment option.

func ContentType

func ContentType(ct string) AttachOption

ContentType sets the "Content-Type" header of an attachment.

type Attachment

type Attachment struct {
	Filename string
	Header   textproto.MIMEHeader
	Content  []byte
}

Attachment is a file attachment.

func (Attachment) ContentType

func (attach Attachment) ContentType() string

ContentType returns the "Content-Type" of the attachment.

type Letter

type Letter struct {
	Subject     string
	From        mail.Address
	To          []mail.Address
	CC          []mail.Address
	BCC         []mail.Address
	Text        string
	HTML        string
	Attachments []Attachment
}

Letter represents a mail.

func New

func New(opts ...WriteOption) Letter

New is an alias to Write()

func Write

func Write(opts ...WriteOption) Letter

Write builds a letter with the provided options.

Example
package main

import (
	"bytes"

	"github.com/bounoable/postdog/letter"
)

func main() {
	let := letter.Write(
		letter.From("Bob", "bob@belcher.test"),
		letter.To("Calvin", "calvin@fishoeder.test"),
		letter.To("Felix", "felix@fishoeder.test"),
		letter.BCC("Jimmy", "jimmy@pesto.test"),
		letter.Subject("Hi, buddy."),
		letter.Text("Have a drink later?"),
		letter.HTML("Have a <strong>drink</strong> later?"),
		letter.MustAttach(bytes.NewReader([]byte("tasty")), "burgerrecipe.txt", letter.ContentType("text/plain")),
	)

	_ = let
}
Output:

func (Letter) HasBCC

func (let Letter) HasBCC(addr mail.Address) bool

HasBCC determines of the letter has addr as a "BCC" recipient.

func (Letter) HasCC

func (let Letter) HasCC(addr mail.Address) bool

HasCC determines of the letter has addr as a "CC" recipient.

func (Letter) HasTo

func (let Letter) HasTo(addr mail.Address) bool

HasTo determines if the letter has addr as a "To" recipient.

func (Letter) RFC

func (let Letter) RFC() string

RFC builds the mail according to the RFC 2822 spec.

func (Letter) String

func (let Letter) String() string

type WriteOption

type WriteOption func(*Letter)

WriteOption configures a letter.

func Attach

func Attach(r io.Reader, filename string, opts ...AttachOption) (WriteOption, error)

Attach attaches the content of r to a letter, with the given filename. It returns an error if it fails to read from r. Available options:

ContentType(): Set the attachment's "Content-Type" header.

func AttachFile

func AttachFile(path, filename string, opts ...AttachOption) (WriteOption, error)

AttachFile attaches the file at path to a letter, with the given filename. It returns an error if it fails to read the file. Available options:

ContentType(): Set the attachment's "Content-Type" header.

func BCC

func BCC(name, addr string) WriteOption

BCC adds a recipient to the "BCC" field of a letter.

func BCCAddress

func BCCAddress(addresses ...mail.Address) WriteOption

BCCAddress adds a recipient to the "BCC" field of a letter.

func CC

func CC(name, addr string) WriteOption

CC adds a recipient to the "CC" field of a letter.

func CCAddress

func CCAddress(addresses ...mail.Address) WriteOption

CCAddress adds a recipient to the "CC" field of a letter.

func Content

func Content(text, html string) WriteOption

Content sets both the HTML and text body of a letter.

func From

func From(name, addr string) WriteOption

From sets the "From" field of a letter.

func FromAddress

func FromAddress(addr mail.Address) WriteOption

FromAddress sets the "From" field of a letter.

func HTML

func HTML(content string) WriteOption

HTML sets the HTML body of a letter.

func Must

func Must(opt WriteOption, err error) WriteOption

Must returns opt if err is nil and panics otherwise.

func MustAttach

func MustAttach(r io.Reader, filename string, opts ...AttachOption) WriteOption

MustAttach does the same as Attach(), but panic if Attach() returns an error.

func MustAttachFile

func MustAttachFile(path, filename string, opts ...AttachOption) WriteOption

MustAttachFile does the same as AttachFile(), but panics if AttachFile() returns an error.

func Subject

func Subject(s string) WriteOption

Subject sets the subject of a letter.

func Text

func Text(content string) WriteOption

Text sets the text body of a letter.

func To

func To(name, addr string) WriteOption

To adds a recipient to the "To" field of a letter.

func ToAddress

func ToAddress(addresses ...mail.Address) WriteOption

ToAddress adds a recipient to the "To" field of a letter.

Jump to

Keyboard shortcuts

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