//设置邮件信息 public void SetMailMessageAndSend(string msg, string[] myMailToArray) { MyMailManager myMailManager = new MyMailManager(); myMailManager.mailFrom = _mailFrom; myMailManager.mailPwd = _mailPwd; DateTime now = DateTime.Now; //邮件主题 string myMailSubject = string.Format("服务异常通知"); //邮件内容 myMailManager.mailSubject = myMailSubject; string myMailBody = string.Format( "<p style=\"padding:0px;margin:0px;line-height:24px;\">Dear All:</p><br/><p style=\"padding:0px;margin:0px;line-height:24px;\">{0}</p><br/>" + "<p style=\"padding:0px;margin:0px;line-height:24px;\">" + "Best regards</p><p style=\"padding:0px;margin:0px;line-height:24px;\">高新区智慧生活 {1}</p>" + "<p style=\"padding:0px;margin:0px;line-height:24px;\"></p>", msg, now.AddDays(-1).ToString("yyyy年MM月dd日")); myMailManager.mailBody = myMailBody; myMailManager.isbodyHtml = true; myMailManager.host = _host; myMailManager.mailToArray = myMailToArray; //发送邮件 myMailManager.Send(); }
public async static Task SendErrorMessage(BizDataContext db, CrawlerException e) { string msg = string.Format("{0},发生了异常,异常信息为:<br/>{1}<br/>更多信息请打开高新区智慧生活后台查看。", e.servicename, e.exceptionbrief); var handlers = await db.Set <T_HTZ_ExceptionHandler>().Where(p => p.ServiceType == e.crawlertype && p.State == v_common.YesState).ToListAsync(); var nearLog = await db.Set <T_HTZ_ExceptionHandlerLog>().Where(p => p.ObjectId == e.serviceid && p.State == v_common.YesState).OrderByDescending(p => p.HTZ_ExceptionHandlerLog_Id).FirstOrDefaultAsync(); if (nearLog != null && nearLog.CreateTime > DateTime.Now.AddHours(-8)) { return; } var mails = handlers.Where(p => !string.IsNullOrEmpty(p.Email)).Select(p => p.Email).ToArray(); if (mails.Length < 1) { return; } var mail = new MyMailManager(); mail.SetMailMessageAndSend(msg, mails); var log = new T_HTZ_ExceptionHandlerLog(); log.CreateTime = DateTime.Now; log.HandlerIdStr = string.Join(",", handlers.Select(p => p.HTZ_ExceptionHandler_Id).ToArray()); log.HTZ_ExceptionHandlerLog_Id = await db.GetNextIdentity_IntAsync(); log.Message = msg; log.MessageType = (int)HTZ_ExceptionHandlerLog_MessageTypeEnum.Mail; log.ObjectId = e.serviceid; log.State = v_common.YesState; await db.InsertAsync(log); }