Documentation ¶
Overview ¶
Package email allows to send emails with attachments. Forked from https://github.com/scorredoira/email
Example ¶
package main import ( "log" "net/mail" "net/smtp" "github.com/scorredoira/email" ) func main() { // compose the message m := email.NewMessage("Hi", "this is the body") m.From = mail.Address{Name: "From", Address: "from@example.com"} m.To = []string{"to@example.com"} // add attachments if err := m.Attach("email.go"); err != nil { log.Fatal(err) } // send it auth := smtp.PlainAuth("", "from@example.com", "pwd", "smtp.zoho.com") if err := email.Send("smtp.zoho.com:587", auth, m); err != nil { log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sendmail ¶
Sendmail sends the message via the /usr/sbin/sendmail interface. It uses LF as line separator, which is suitable for most MTAs on Linux/Unix.
qmail: "Unlike Sendmail, qmail requires locally-injected messages to use Unix newlines (LF only)."
postfix: "The SMTP record delimiter is CRLF. Postfix removes it (as well as invalid CR characters at the end of a record) while receiving mail via SMTP, and adds it when sending mail via SMTP."
sendmail: The system's line separator seems to be default, as the -bs flag changes that behavior.
Types ¶
type Attachment ¶
Attachment represents an email attachment.
type Message ¶
type Message struct { From mail.Address To []string Cc []string Bcc []string ReplyTo string Subject string Body string BodyContentType string Attachments map[string]*Attachment }
Message represents a smtp message.
func NewHTMLMessage ¶
NewHTMLMessage returns a new Message that can compose an HTML email with attachments
func NewMessage ¶
NewMessage returns a new Message that can compose an email with attachments
func (*Message) AttachBuffer ¶
AttachBuffer attaches a binary attachment.