Documentation
¶
Overview ¶
gophermail is a simple package for sending mail using net/smtp.
Features:
- Poviding both plain text and HTML message bodies
- Attachments with data fed from an io.Reader
- Reply-To header
- To, Cc, and Bcc recipients
Notes:
- UTF-8 encoding is always assumed.
- Message bodies are base64 encoded instead of the more readable quoted-printable encoding.
Known Issues:
- `Subject: ` headers longer than 75 characters are not wrapped into multiple encoded-words as per RFC 2047. Use short subjects.
TODO:
- Use quoted-printable encoding for message bodies.
- Properly wrap `Subject:` headers longer than 75 characters.
- Add support for `Sender:` header.
- Add support for multiple `From:` and `Reply-To:` addresses.
- Auto-add a `Date:` header. i.e. "Date: " + time.Now().UTC().Format(time.RFC822)
Index ¶
- Variables
- func NewBase64MimeEncoder(w io.Writer) io.WriteCloser
- func SendMail(addr string, a smtp.Auth, msg *Message) error
- type Attachment
- type Message
- func (m *Message) AddBcc(addresses ...string) error
- func (m *Message) AddCc(addresses ...string) error
- func (m *Message) AddTo(addresses ...string) error
- func (m *Message) Bytes() ([]byte, error)
- func (m *Message) SendMailArgs(addr string, auth smtp.Auth) (func() (addr string, auth smtp.Auth, from string, to []string, msg []byte), ...)
- func (m *Message) SetFrom(address string) error
- func (m *Message) SetReplyTo(address string) error
Constants ¶
This section is empty.
Variables ¶
var ErrMissingFromAddress = errors.New("No from address specified.")
var ErrMissingRecipient = errors.New("No recipient specified. At one To, Cc, or Bcc recipient is required.")
Functions ¶
func NewBase64MimeEncoder ¶
func NewBase64MimeEncoder(w io.Writer) io.WriteCloser
Types ¶
type Attachment ¶
type Attachment struct {
// Name must be set to a valid file name.
Name string
// Optional.
// Uses mime.TypeByExtension and falls back
// to application/octet-stream if unknown.
ContentType string
Data io.Reader
}
An Attachment represents an email attachment.
type Message ¶
type Message struct {
// Technically this could be a list of addresses but we don't support that. See RFC 2822 s3.6.2.
From mail.Address
// Technically this could be a list of addresses but we don't support that. See RFC 2822 s3.6.2.
ReplyTo mail.Address // optional
To, Cc, Bcc []mail.Address
Subject string // optional
Body bytes.Buffer // optional
HTMLBody bytes.Buffer //optional
Attachments []Attachment // optional
// Extra mail headers.
Headers mail.Header
}
A Message represents an email message. Addresses may be of any form permitted by RFC 5322.
func (*Message) AddBcc ¶
AddBcc creates a mail.Address and adds it to the list of Bcc addresses in the message
func (*Message) AddCc ¶
AddCc creates a mail.Address and adds it to the list of Cc addresses in the message
func (*Message) AddTo ¶
AddTo creates a mail.Address and adds it to the list of To addresses in the message
func (*Message) SendMailArgs ¶
func (m *Message) SendMailArgs(addr string, auth smtp.Auth) ( func() ( addr string, auth smtp.Auth, from string, to []string, msg []byte, ), error)
SendMailArgs returns a function that is guaranteed to cleanly return all the arguments necessary to send a mail using smtp.SendMail. If for some reason an error occurs when generating those arguments, that error is passed out alongisde the SendMailArgFunc so that it can avoid being invoked.
func (*Message) SetFrom ¶
SetFrom creates a mail.Address and assigns it to the message's From field.
func (*Message) SetReplyTo ¶
SetReplyTo creates a mail.Address and assigns it to the message's ReplyTo field.
