smtp设置

  1. // 126
  2. "user": "zetaleee@126.com",
  3. "pass": "DGXZPKILMIIKVRDM",
  4. "host": "smtp.126.com",
  5. "port": "465",
  6. // outlook
  7. "user": "zetaleee@outlook.com",
  8. "pass": "mima",
  9. "host": "smtp-mail.outlook.com",
  10. "port": "587",

“gopkg.in/gomail.v2”

实例

  1. m := gomail.NewMessage()
  2. m.SetHeader("From", "alex@example.com")
  3. m.SetHeader("To", "bob@example.com", "cora@example.com")
  4. m.SetAddressHeader("Cc", "dan@example.com", "Dan")
  5. m.SetHeader("Subject", "Hello!")
  6. m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
  7. m.Attach("/home/Alex/lolcat.jpg")
  8. d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
  9. // Send the email to Bob, Cora and Dan.
  10. if err := d.DialAndSend(m); err != nil {
  11. panic(err)
  12. }