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 ¶
- func DecodeAddress(rawheader string) ([]string, error)
- type Message
- func (m *Message) Forward(from string, to []string, cc []string, body string) *Message
- func (m *Message) Marshal() ([]byte, error)
- func (m *Message) Receivers() string
- func (m *Message) Reply(from, body string, cc []string) *Message
- func (m *Message) ReplyAll(from, body string) *Message
- func (m *Message) Send() error
- type Part
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeAddress ¶
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 ¶
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) Marshal ¶
Marshal builds a textual representation of a message with headers and quoted-printable body. It ignores ReturnPath, HTML and Parts.