1 package email 2 3 import ( 4 "errors" 5 "gopkg.in/gomail.v2" 6 ) 7 8 var dialer *gomail.Dialer 9 10 func Reset(host string, port int, username, password string) { 11 dialer = gomail.NewDialer(host, port, username, password) 12 } 13 func SendText(to, subject, body string) error { 14 if dialer == nil { 15 return errors.New("invalid dialer") 16 } 17 message := gomail.NewMessage() 18 message.SetHeader("From", dialer.Username) 19 message.SetHeader("Subject", subject) 20 message.SetBody("text/plain", body) 21 err := dialer.DialAndSend(message) 22 if err != nil { 23 return err 24 } 25 return nil 26 }
标签:return,string,err,golang,dialer,v2,gomail,message From: https://www.cnblogs.com/liudongcai/p/17749745.html