Ejemplo n.º 1
0
        /// <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(); //清理数据
        }