func NewMessageID(host string) string
NewMessageID generates a cryptographically unique RFC 2822 3.6.4 Message ID (not including angle brackets).
Attachment defines an e-mail attachment. They are read lazily.
type Attachment struct { // Filename is the name to give the attachment in the email Filename string // Mimetype e.g. "application/pdf". // If an empty string, then attempts to automatically detect based on filename extension. Mimetype string // Reader is a lazy reader. e.g. a function that returns the result of os.Open. Reader func() (io.ReadCloser, error) }
func FileAttachment(src string) *Attachment
FileAttachment returns an Attachment from a file path. The file at that path is lazily opened at the time the attachment is sent.
func (a *Attachment) MarshalJSON() ([]byte, error)
Implements the json.Marshal interface. Note that the JSON content is ALWAYS Base64 encoded (with whitespace).
func (a *Attachment) UnmarshalJSON(data []byte) error
Implements the json.Unarshal interface. Note that the JSON content is ALWAYS Base64 encoded (with whitespace).
Envelope wraps an Email with some SMTP protocol information for extra control.
type Envelope struct { // ReturnPath is the sender in the FROM SMTP command. // // Often, this should match the Email From address. // // In the cause of autoreplies (like "Out of Office" or bounces or delivery // status notifications) this should be an empty string to stop an infinite // loop of bounces. ReturnPath string // ReceiptTo is a list of recipients. This is normally automatically // generated from the Email To/CC/BCC addresses. ReceiptTo []string }
Message defines a multipart e-mail (including headers, HTML body, plain text body, and attachments).
Use the `headers` parameter to specify additional headers. Note that `mail.Header` maps keys to a *list* of strings, because some headers may appear multiple times.
type Message struct { ID string // Message-ID header, excluding angle brackets From mail.Address To []mail.Address Cc []mail.Address Bcc []mail.Address Subject string // Headers are additional headers for the message. The combination of a // header and a value as strings must not exceed a length of 996 // characters. Longer values CANNOT be supported with folding white space // syntax without advance knowledge (special cases are possible but not // currently implemented). Headers mail.Header // Html is a HTML-encoded version of the message. Lines must not exceed // 998 characters. Html string // Text is a plain-text version of the message. It is your responsibility // to ensure word-wrapping. Lines must not exceed 998 characters. Text string // Attachments is a lazily-loaded sequence of attachments. May be nil. Attachments []*Attachment }
func (e *Message) Write(dest io.Writer) error
Write writes a multipart Email to dest.
func (e *Message) WriteCompat(dest io.Writer) error
WriteCompat is like Write, however very long headers (caused, for example, by sending a message with many To addresses, or a subject that is too long) are not encoded using folding white space and instead cause an error.