Skip to content

Instantly share code, notes, and snippets.

@johnsonz
Last active July 21, 2016 01:47
Show Gist options
  • Save johnsonz/9e13053d74ef32ffa5ae0d43b5967e38 to your computer and use it in GitHub Desktop.
Save johnsonz/9e13053d74ef32ffa5ae0d43b5967e38 to your computer and use it in GitHub Desktop.
使用go来发送邮件
package main
import "gopkg.in/gomail.v2"
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "you@example.com")
m.SetHeader("To", "you@example.com", "you@example.com")
m.SetAddressHeader("Cc", "dan@example.com", "Dan")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
m.Attach("/home/Alex/lolcat.jpg")
d := gomail.NewDialer("smtp.gmail.com", 465, "you@example.com", "123456")
// Send the email to Bob, Cora and Dan.
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment