/// <summary> /// /// </summary> public void SendMailtoDes(List <EmailAndSmsModel> list) { if (list == null) { throw new ArgumentNullException("list"); } _smtp.UseDefaultCredentials = false; _smtp.Credentials = new NetworkCredential(UserMail, Password); foreach (var t in list) { _objMailMessage = new MailMessage { Priority = MailPriority.Normal, From = new MailAddress(UserMail) }; _objMailMessage.To.Add(new MailAddress(t.Address)); _objMailMessage.IsBodyHtml = true; _objMailMessage.Subject = t.Title; _objMailMessage.Body = t.Body; try { _smtp.Send(_objMailMessage); var warndetailbll = new WarnDetailBll(); var warndetail = new WarnDetail { ProcessFlag = 1 }; warndetailbll.Modify(warndetail); } catch (Exception e) { } } }
/// <summary> /// 发送短信 /// </summary> public string SendSms() { var warndetailBll = new WarnDetailBll(); var smsSuccessList = new Dictionary <uint, string>(); var data = warndetailBll.FindBySms(); if (data.Rows.Count <= 0) { return("没有短信数据。"); } foreach (DataRow dataRow in data.Rows)//这里是全部的信息 { var id = dataRow["id"].ToString(); var warnid = dataRow["WARNRECID"].ToString(); var warncontext = dataRow["WARNCONTEXT"].ToString(); var strContent = ResplaceTemplateStr(warncontext, warnid); var warntarget = dataRow["ADDRESS"].ToString(); var warntargetList = warntarget.Split(';'); foreach (var s in warntargetList)//这里是全部的电话 { try { var num = SmsApi.SMSSendMessage(strContent, s); smsSuccessList.Add(num, id); Thread.Sleep(100); } catch (Exception) { continue; } } } var successNum = 0; var sendingNum = 0; var failureNum = 0; foreach (var u in smsSuccessList) { var queryData = SmsApi.SMSQuery(u.Key); WarnDetail warndetail = null; switch (queryData) { //发送成功 case 1: warndetail = new WarnDetail { Id = u.Value, ProcessFlag = 1, IsSuccess = 1, SendDT = DateTime.Now, UpdateDT = DateTime.Now }; successNum++; break; //正在发送中 case -1: warndetail = new WarnDetail { Id = u.Value, IsSuccess = 0, ProcessFlag = 1, SendDT = DateTime.Now, UpdateDT = DateTime.Now }; sendingNum++; break; //发送失败 case 0: warndetail = new WarnDetail { Id = u.Value, ProcessFlag = 1, IsSuccess = 2, SendDT = DateTime.Now, UpdateDT = DateTime.Now }; failureNum++; break; default: break; } warndetailBll.Modify(warndetail); } return("全部已发送:" + smsSuccessList.Count + "条(其中,成功:" + successNum + "条,失败:" + failureNum + "条,正在发送:" + sendingNum + "条)"); }