Added an example using the CRAM-MD5 authentication mechanism

Fixes #52
This commit is contained in:
Alexandre Cesaro 2016-03-05 17:35:32 +01:00
parent 3f18d6d1a6
commit 0773d147cc
1 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"html/template"
"io"
"log"
"net/smtp"
"time"
"gopkg.in/gomail.v2"
@ -113,6 +114,24 @@ func Example_noAuth() {
}
}
// Send an email using the CRAM-MD5 authentication mechanism.
func Example_CRAM_MD5() {
m := gomail.NewMessage()
m.SetHeader("From", "from@example.com")
m.SetHeader("To", "to@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "Hello!")
d := gomail.Dialer{
Host: "localhost",
Port: 587,
Auth: smtp.CRAMMD5Auth("username", "secret"),
}
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}
// Send an email using an API or postfix.
func Example_noSMTP() {
m := gomail.NewMessage()