/** 解析xml文件 **/ func ParseXml(configFile string) { file, err := os.Open(configFile) if err != nil { Utils.LogPanicErr(err) return } xmlObj := xml.NewDecoder(file) err = xmlObj.Decode(&vsConfig) if err != nil { Utils.LogPanicErr(err) return } Utils.LogInfo("parse xml=%v\n", vsConfig) }
func (j *Jobsms) Run() { for { Utils.LogInfo("Jobsms delay %d Second", Config.GetLoopTime().Sms) time.Sleep(time.Second * Config.GetLoopTime().Sms) beanstalkd, err := lentil.Dial(Config.GetBeanstalk().Server) if err != nil { Utils.LogPanicErr(err) } else { err = beanstalkd.Use(Config.GetBeanstalk().MobileQueue) } if err != nil { Utils.LogPanicErr(err) } else { for i := 0; i < 10; i++ { job, err := beanstalkd.PeekReady() if err != nil { //Utils.LogPanicErr(err) break } else { body := strings.SplitN(string(job.Body), "\t", 2) if len(body) == 2 { r, err := base64.StdEncoding.DecodeString(body[1]) if err == nil { fmt.Printf("Job id: %d \nmobile: %s \nbody: %s", job.Id, body[0], string(r)) e := SendSms(body[0], string(r)) if e != nil { Utils.LogPanicErr(e) } } } beanstalkd.Delete(job.Id) } } } } }
//http://sendcloud.sohu.com func SendMailBySohu(to, subject, body string) (err error) { resp, err := http.PostForm(Config.GetUrl().MailApi, url.Values{"to": {to}, "subject": {subject}, "html": {body}}) if err != nil { return err } defer resp.Body.Close() res, err := ioutil.ReadAll(resp.Body) if err != nil { Utils.LogPanicErr(err) } Utils.LogInfo(string(res)) return nil }
func (j *Jobmail) Run() { for { Utils.LogInfo("Jobmail delay %d Second", Config.GetLoopTime().Mail) time.Sleep(time.Second * Config.GetLoopTime().Mail) beanstalkd, err := lentil.Dial(Config.GetBeanstalk().Server) if err != nil { Utils.LogPanicErr(err) } else { err = beanstalkd.Use(Config.GetBeanstalk().MailQueue) } if err != nil { Utils.LogPanicErr(err) } else { for i := 0; i < 10; i++ { job, err := beanstalkd.PeekReady() if err != nil { //Utils.LogPanicErr(err) break } else { body := strings.SplitN(string(job.Body), "\t", 4) if len(body) == 4 { r, err := base64.StdEncoding.DecodeString(body[3]) if err == nil { fmt.Printf("Job id: %d \nmail to:%s \nsubject:%s\nbody: , %s", job.Id, body[0], body[1], string(r)) //SendMail( body[0], body[1], string(r), body[2]) SendMailBySohu(body[0], body[1], string(r)) } } beanstalkd.Delete(job.Id) } } } } }
func SendMail(to, subject, body, mailtype string) { hp := strings.Split(Config.GetSmtp().Host, ":") auth := LoginAuth(Config.GetSmtp().Username, Config.GetSmtp().Password) var content_type string if mailtype == "html" { content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8" } else { content_type = "Content-Type: text/plain" + "; charset=UTF-8" } from := Config.GetSmtp().From msg := []byte("To: " + to + "\r\nFrom: " + from + "<" + Config.GetSmtp().Username + "@" + hp[0] + ">\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body) send_to := strings.Split(to, ";") err := smtp.SendMail(Config.GetSmtp().Host, auth, Config.GetSmtp().Username, send_to, msg) if err != nil { Utils.LogPanicErr(err) } }