/// <summary> /// 开始群发邮件 /// </summary> private void sendStart() { UpdateSendSettingStatus(1); //开始发送并初始化数据 smtpList = SmtpListHelper.SelectListByAll().Where(p => p.Status == 0).ToList(); if (smtpList.Count == 0) { WriteLog("SMTP列表为空!"); if (uiDone != null) { uiDone(); } return; } smtpInfo = smtpList[0]; //默认使用第一个SMTP发送 template = templateList.Where(t => t.TemplateID == sendSetting.TemplateID).FirstOrDefault(); if (template.IsNull() || template.TemplateID.IsNull()) { WriteLog("找不到模版ID:" + sendSetting.TemplateID); if (uiDone != null) { uiDone(); } return; } WriteLog(""); WriteLog(template.Subject + "|" + NetHelper.GetNetName(sendSetting.ConnectType.Value) + "|" + smtpInfo.SmtpServer + "|" + smtpInfo.UserName + " 开始发送!"); email = new Email(smtpInfo.SmtpServer, smtpInfo.SmtpPort.Value) .Ssl(smtpInfo.SSL.Value) .Credentials(smtpInfo.UserName, smtpInfo.SPassword) .IsBodyHtml(template.IsHTML.Value) .Timeout(3000); int state = SendEmails(); if (state == -1) { return; //停止发送邮件 } if (state == 0) { UpdateSendSettingStatus(2); //正常发送完成时 标记全部发送完成 } WriteLog(template.Subject + (state == 0 ? " 已发送完成!" : " 已停止发送!")); //此处可邮件通知 if (uiDone != null) { uiDone(); } clear(); //清理数据 }
public static void Smtps(bool exit = false) { WriteLog("smtps(ss) 显示SMTP列表"); WriteLog("==============================================================================="); IList <SmtpList> smtpList = SmtpListHelper.SelectListByAll(); foreach (var smtp in smtpList) { WriteLog("{0},{1},{2}", smtp.SmtpServer, smtp.SmtpPort, smtp.UserName); } WriteLog("count:{0}", smtpList.Count); WriteLog("END"); Input(exit); }
/// <summary> /// 开始群发邮件 /// </summary> /// <param name="msg">通知消息</param> /// <param name="done">完成执行</param> public void Start(Action <string> msg = null, Pub.Class.Action done = null) { exit = false; uiMsg = msg; uiDone = done; thread = new Thread(() => { smtpList = SmtpListHelper.SelectListByAll(); sendSetting = SendSettingHelper.SelectByID(1); templateList = HtmlTemplateHelper.SelectListByAll().Where(p => p.Status == 0).ToList(); sendStart(); }); thread.IsBackground = true; thread.Start(); }