msg

package
v0.0.0-...-90b322d Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareBodies

func CompareBodies(t *testing.T, got, want string)

Types

type Encoding

type Encoding string

Encoding represents a MIME encoding scheme like quoted-printable or base64.

const (
	// QuotedPrintable represents the quoted-printable encoding as defined in
	// RFC 2045.
	QuotedPrintable Encoding = "quoted-printable"
	// Base64 represents the base64 encoding as defined in RFC 2045.
	Base64 Encoding = "base64"
	// Unencoded can be used to avoid encoding the body of an email. The headers
	// will still be encoded using quoted-printable encoding.
	Unencoded Encoding = "8bit"
)

type File

type File struct {
	Name     string
	Header   map[string][]string
	CopyFunc func(w io.Writer) error
}

func (*File) SetHeader

func (f *File) SetHeader(field, value string)

type FileSetting

type FileSetting func(*File)

A FileSetting can be used as an argument in Message.Attach or Message.Embed.

func Rename

func Rename(name string) FileSetting

Rename is a file setting to set the name of the attachment if the name is different than the filename on disk.

func SetCopyFunc

func SetCopyFunc(f func(io.Writer) error) FileSetting

SetCopyFunc is a file setting to replace the function that runs when the msg is sent. It should copy the content of the file to the io.Writer.

The default copy function opens the file with the given filename, and copy its content to the io.Writer.

func SetHeader

func SetHeader(h map[string][]string) FileSetting

SetHeader is a file setting to set the MIME header of the msg part that contains the file content.

Mandatory headers are automatically added if they are not set when sending the email.

type Header map[string][]string

type Message

type Message struct {
	Header      Header
	Parts       []*Part
	Attachments []*File
	Embedded    []*File
	Charset     string
	Encoding    Encoding
	HEncoder    mime.MimeEncoder
	Buf         bytes.Buffer
}

Message represents an email.

func NewMessage

func NewMessage(settings ...MessageSetting) *Message

NewMessage creates a new msg. It uses UTF-8 and quoted-printable encoding by default.

func (*Message) AddAlternative

func (m *Message) AddAlternative(contentType, body string, settings ...PartSetting)

AddAlternative adds an alternative part to the msg.

It is commonly used to send HTML emails that default to the plain text version for backward compatibility. AddAlternative appends the new part to the end of the msg. So the plain text part should be added before the HTML part. See http://en.wikipedia.org/wiki/MIME#Alternative

func (*Message) AddAlternativeWriter

func (m *Message) AddAlternativeWriter(contentType string, f func(io.Writer) error, settings ...PartSetting)

AddAlternativeWriter adds an alternative part to the msg. It can be useful with the text/template or html/template packages.

func (*Message) Attach

func (m *Message) Attach(filename string, settings ...FileSetting)

Attach attaches the files to the email.

func (*Message) Embed

func (m *Message) Embed(filename string, settings ...FileSetting)

Embed embeds the images to the email.

func (*Message) FormatAddress

func (m *Message) FormatAddress(address, name string) string

FormatAddress formats an address and a name as a valid RFC 5322 address.

func (*Message) FormatDate

func (m *Message) FormatDate(date time.Time) string

FormatDate formats a date as a valid RFC 5322 date.

func (*Message) GetFrom

func (m *Message) GetFrom() (string, error)

func (*Message) GetHeader

func (m *Message) GetHeader(field string) []string

GetHeader gets a header field.

func (*Message) GetRecipients

func (m *Message) GetRecipients() ([]string, error)

func (*Message) HasAlternativePart

func (m *Message) HasAlternativePart() bool

func (*Message) HasMixedPart

func (m *Message) HasMixedPart() bool

func (*Message) HasRelatedPart

func (m *Message) HasRelatedPart() bool

func (*Message) Reset

func (m *Message) Reset()

Reset resets the msg so it can be reused. The msg keeps its previous settings so it is in the same state that after a call to NewMessage.

func (*Message) SetAddressHeader

func (m *Message) SetAddressHeader(field, address, name string)

SetAddressHeader sets an address to the given header field.

func (*Message) SetBody

func (m *Message) SetBody(contentType, body string, settings ...PartSetting)

SetBody sets the body of the msg. It replaces any content previously set by SetBody, AddAlternative or AddAlternativeWriter.

func (*Message) SetDateHeader

func (m *Message) SetDateHeader(field string, date time.Time)

SetDateHeader sets a date to the given header field.

func (*Message) SetHeader

func (m *Message) SetHeader(field string, value ...string)

SetHeader sets a value to the given header field.

func (*Message) SetHeaders

func (m *Message) SetHeaders(h map[string][]string)

SetHeaders sets the msg headers.

func (*Message) WriteTo

func (m *Message) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo. It dumps the whole msg into w.

type MessageSetting

type MessageSetting func(m *Message)

A MessageSetting can be used as an argument in NewMessage to configure an email.

func SetCharset

func SetCharset(charset string) MessageSetting

SetCharset is a msg setting to set the charset of the email.

func SetEncoding

func SetEncoding(enc Encoding) MessageSetting

SetEncoding is a msg setting to set the encoding of the email.

type Part

type Part struct {
	ContentType string
	Copier      func(io.Writer) error
	Encoding    Encoding
}

type PartSetting

type PartSetting func(*Part)

A PartSetting can be used as an argument in Message.SetBody, Message.AddAlternative or Message.AddAlternativeWriter to configure the part added to a msg.

func SetPartEncoding

func SetPartEncoding(e Encoding) PartSetting

SetPartEncoding sets the encoding of the part added to the msg. By default, parts use the same encoding than the msg.

Jump to

Keyboard shortcuts

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