一个简单而强大用于发送电子邮件的Go包:Gomail

jopen 11年前

这个包提供了一个简单的接口来发送电子邮件。它需要Go 1.2或更新的版本。

特性

  • Dead-simple API
  • 高度灵活Highly flexible
  • Backward compatibility promise
  • 支持HTML和文本模板。Supports HTML and text templates
  • 支持附件
  • 嵌入图片
  • Automatic encoding of special characters
  • Well-documented
  • High test coverage

示例:

package main    import (      "gopkg.in/gomail.v1"  )    func main() {      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>!")        f, err := gomail.OpenFile("/home/Alex/lolcat.jpg")      if err != nil {          panic(err)      }      msg.Attach(f)        // Send the email to Bob, Cora and Dan      mailer := gomail.NewMailer("smtp.example.com", "user", "123456", 25)      if err := mailer.Send(msg); err != nil {          panic(err)      }  }

项目主页:http://www.open-open.com/lib/view/home/1413516569465