Documentation ¶
Overview ¶
Deprecated, use https://github.com/go-gomail/gomail instead. Package gomail provides a simple interface to easily write and send emails.
Example:
package main import ( "log" "github.com/alexcesaro/mail/gomail" ) func main() { msg := gomail.NewMessage() msg.SetAddressHeader("From", "alex@example.com", "Alex") msg.SetHeader("To", "bob@example.com") msg.AddHeader("To", "cora@example.com") msg.SetHeader("Subject", "Hello!") msg.SetBody("text/plain", "Hello Bob and Cora!") msg.AddAlternative("text/html", "Hello <b>Bob</b> and <i>Cora</i>!") if err := msg.Attach("/home/Alex/lolcat.jpg") { log.Println(err) return } m := gomail.NewMailer("smtp.example.com", "user", "123456", 25) if err := m.Send(msg); err != nil { // This will send the email to Bob and Cora log.Println(err) } }
Index ¶
- Constants
- type Mailer
- type Message
- func (msg *Message) AddAddressHeader(field, address, name string)
- func (msg *Message) AddAlternative(contentType, body string)
- func (msg *Message) AddDateHeader(field string, date time.Time)
- func (msg *Message) AddHeader(field, value string)
- func (msg *Message) Attach(filename string) error
- func (msg *Message) DelHeader(field string)
- func (msg *Message) Export() (*mail.Message, error)
- func (msg *Message) GetBodyWriter(contentType string) io.Writer
- func (msg *Message) GetHeader(field string) []string
- func (msg *Message) SetAddressHeader(field, address, name string)
- func (msg *Message) SetBody(contentType, body string)
- func (msg *Message) SetDateHeader(field string, date time.Time)
- func (msg *Message) SetHeader(field, value string)
Constants ¶
const ( // QuotedPrintable represents the quoted-printable encoding as defined in // RFC 2045. QuotedPrintable = "quoted-printable" // Base64 represents the base64 encoding as defined in RFC 2045. Base64 = "base64" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mailer ¶
type Mailer struct {
// contains filtered or unexported fields
}
A Mailer represents an SMTP server.
func NewCustomMailer ¶
NewCustomMailer creates a mailer using any authentication mechanism.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message represents a mail message.
func NewCustomMessage ¶
NewCustomMessage creates a new message that will use the given encoding and charset.
func NewMessage ¶
func NewMessage() *Message
NewMessage creates a new UTF-8 message using quoted-printable encoding.
func (*Message) AddAddressHeader ¶
AddAddressHeader adds an address to the given header field.
func (*Message) AddAlternative ¶
AddAlternative adds an alternative body to the message. Usually used to provide both an HTML and a text version of the message.
func (*Message) AddDateHeader ¶
AddDateHeader adds a date to the given header field.
func (*Message) GetBodyWriter ¶
GetBodyWriter gets a writer that writes to the body. It can be useful with the templates from packages text/template or html/template.
Example:
w := msg.GetBodyWriter("text/plain") t := template.Must(template.New("example").Parse("Hello {{.}}!")) t.Execute(w, "Bob")
func (*Message) SetAddressHeader ¶
SetAddressHeader sets an address to the given header field.
func (*Message) SetDateHeader ¶
SetDateHeader sets a date to the given header field.