package sendMail import ( "fmt" "net/smtp" "strings" ) type senderInfo struct { User string `jsob:user` Passwd string `json:passwd` Host_port string `json:host_port` Mailaddr string `json:mailaddr` Subject string `json:subject` } func (self *senderInfo) SendMail(toList, body string) error { head := fmt.Sprintf("To: %v\r\nSubject: %v\r\nContent-Type: text/plain;charset=UTF-8\r\n\r\n", toList, self.Subject) host := strings.Split(self.Host_port, ":") if len(host) != 2 { return fmt.Errorf("%v not a valid host_port", self.Host_port) } auth := smtp.PlainAuth("", self.User, self.Passwd, host[0]) return smtp.SendMail(self.Host_port, auth, self.Mailaddr, strings.Split(toList, ";"), []byte(head+body)) }
有疑问加站长微信联系(非本文作者)