all repos — mail2 @ 374a1e795e33e915e44adde14b1aa1a2a11826ad

fork of github.com/joegrasse/mail with some changes

Add another usage example
Joe Grasse hide@my.email
Mon, 20 Mar 2017 08:40:48 -0500
commit

374a1e795e33e915e44adde14b1aa1a2a11826ad

parent

833141fcdaebe89217997a07c789ef959581b494

1 files changed, 44 insertions(+), 0 deletions(-)

jump to
M README.mdREADME.md

@@ -27,3 +27,47 @@ fmt.Println("Email Sent")

} } ``` + +**More Advanced Usage** + +```go +package main + +import ( + "fmt" + + "github.com/joegrasse/mail" +) + +func main() { + htmlBody := + `<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Hello Gophers!</title> + </head> + <body> + <p>This is the <b>Go gopher</b>.</p> + <p><img src="cid:Gopher.png" alt="Go gopher" /></p> + <p>Image created by Renee French</p> + </body> + </html>` + + email := mail.New() + email.SetPriority(mail.PriorityHigh) + email.SetFrom("From Example <from@example.com>").AddTo("to@example.com").AddCc("otherto@example.com").SetSubject("New Go Email") + + email.SetBody("text/plain", "Hello Gophers!") + email.AddAlternative("text/html", htmlBody) + + email.AddInline("/path/to/image.png", "Gopher.png") + + err := email.Send("smtp.example.com:25") + + if err != nil { + fmt.Println(err) + } else { + fmt.Println("Email Sent") + } +} +```