一個簡單而強大用于發送電子郵件的Go包:Gomail
這個包提供了一個簡單的接口來發送電子郵件。它需要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)
}
}
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!