Added an example

This commit is contained in:
Alexandre Cesaro 2015-07-16 23:06:29 +02:00
parent d49395d6c9
commit 9775d1d734
1 changed files with 33 additions and 0 deletions

33
example_test.go Normal file
View File

@ -0,0 +1,33 @@
package gomail_test
import (
"fmt"
"io"
"strings"
"github.com/go-gomail/gomail"
)
func ExampleSend() {
msg := gomail.NewMessage()
msg.SetHeader("From", "alex@example.com")
msg.SetHeader("To", "bob@example.com", "cora@example.com")
msg.SetAddressHeader("Cc", "dan@example.com", "Dan")
msg.SetHeader("Subject", "Hello!")
msg.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
s := gomail.SendFunc(func(from string, to []string, msg io.WriterTo) error {
// Implements you email-sending function, for example by calling
// an API, or running postfix, etc.
fmt.Println("From:", from)
fmt.Println("To:", strings.Join(to, ", "))
return nil
})
if err := gomail.Send(s, msg); err != nil {
panic(err)
}
// Output:
// From: alex@example.com
// To: bob@example.com, cora@example.com, dan@example.com
}