package main import ( "github.com/scorredoira/email" "net/smtp" "log" ) func main() { m := email.NewMessage("Hi", "this is a test") m.From = "jackma_xx@126.com" m.To = []string{"xxxx@163.com"} err := m.Attach("test.jpg") if err != nil { log.Println(err) } err = email.Send("smtp.126.com:25", smtp.PlainAuth("", "jackma_xx@126.com", "MAILPWD", "smtp.126.com"), m) }
里面用到了开源的
"github.com/scorredoira/email",利用 go get github.com/scorredoira/email 安装即可
有疑问加站长微信联系(非本文作者)