func SendMonitorStatus(ret map[string]bool,smtpHost,smtpPort,smtpUser,smtpPass,toSendList string) (bool,error) { t := time.Now() year,month,day := t.Date() curtime := fmt.Sprintf("%d-%d-%d %d:%d",year,month,day,t.Hour(),t.Minute()) auth := smtp.PlainAuth("", smtpUser,smtpPass,smtpHost) to := strings.Split(toSendList,",") header := make(map[string]string) header["From"] = smtpUser header["To"] = to[0] header["Date"] = curtime header["Subject"] = "文件同步报告" header["Content-Type"] = "text/html;charset=UTF-8" body := "" for k,v := range ret{ body+= fmt.Sprintf("%s:%v",k,v) } msg := "" for k,v := range header{ msg += fmt.Sprintf("%s:%s\r\n",k,v) } msg += "\r\n"+body conn,err := tls.Dial("tcp",smtpHost+":"+smtpPort,nil) if err != nil { HandleWarning(err) } co,err := smtp.NewClient(conn,smtpHost) if err != nil { HandleWarning(err) } defer co.Close() if auth != nil { if ok,_ := co.Extension("AUTH");ok { if err = co.Auth(auth);err != nil { HandleError(err) } } } if err = co.Mail(smtpUser); err != nil { HandleError(err) } for _,addr := range to { if err = co.Rcpt(addr); err != nil { HandleWarning(err) } } w,err := co.Data() if err != nil { HandleWarning(err) } _,err = w.Write([]byte(msg)) if err != nil { HandleWarning(err) } err = w.Close() if err != nil { HandleWarning(err) } co.Quit() return true,nil }