mail

package module
v0.0.0-...-f6c8e32 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2016 License: BSD-3-Clause Imports: 19 Imported by: 0

README

mail

Email parser and generator

This package doesn't expose any email internals, but is suitable and easy to use in scenarios like parse message, convert html bits to text, determine customer by email address, create ticket in a ticket system and reply back with TT ID.

Documentation

Overview

Package mail implements mail parser and generator.

This package doesn't expose any email internals, but is suitable and easy to use in scenarios like parse message, convert html bits to text, determine customer by email address, create ticket in a ticket system and reply back with TT ID.

msg, err := mail.ReadMessage(r.Body)
if err != nil {
	return err
}

customer, err := FindCustomer(msg.From)
if err != nil {
	return err
}

tt, err := customer.CreateTT(msg.Subject, msg.Text)
if err != nil {
	return err
}

nmsg := msg.Reply(emailHelpdesk, fmt.Sprintf(ReplyFmt, tt.ID), nil)
nmsg.Subject = fmt.Sprintf("Re: [TT:%v] %v", tt.ID, msg.Subject)
if err := nmsg.Send(); err != nil {
	return err
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAddress

func DecodeAddress(rawheader string) ([]string, error)

DecodeAddress parses address line.

Types

type Message

type Message struct {
	ID         string
	ReturnPath string
	From       string
	To         []string
	CC         []string
	Subject    string
	Date       time.Time
	// IsHTML is set when Body contains HTML converted to text.
	// Also used when marshalling to determine content-type.
	IsHTML  bool
	HTML    string
	Body    string
	Parts   []Part
	Headers map[string]string
}

Message represents an email message.

func NewMessage

func NewMessage(from string, to []string, cc []string, subject, body string, headers map[string]string) *Message

NewMessage creates new message.

func ReadMessage

func ReadMessage(r io.Reader) (*Message, error)

ReadMessage reads message from r. Using Send() on read messages can result in garbage in headers, make sure to remove unnecessary ones, before sending.

func (*Message) Forward

func (m *Message) Forward(from string, to []string, cc []string, body string) *Message

Forward generates forward message for m.

func (*Message) Marshal

func (m *Message) Marshal() ([]byte, error)

Marshal builds a textual representation of a message with headers and quoted-printable body. It ignores ReturnPath, HTML and Parts.

func (*Message) Receivers

func (m *Message) Receivers() string

Receivers return joined list from To and CC separated with comma.

func (*Message) Reply

func (m *Message) Reply(from, body string, cc []string) *Message

Reply generates reply to m.

func (*Message) ReplyAll

func (m *Message) ReplyAll(from, body string) *Message

ReplyAll generates reply all to m.

func (*Message) Send

func (m *Message) Send() error

Send sends message via 127.0.0.1:25.

type Part

type Part struct {
	Name string
	Data []byte
}

Part represents attachment in message.

Jump to

Keyboard shortcuts

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