Beispiel #1
0
 private void mnuAdd_Click(object sender, EventArgs e)
 {
     tabControl1.SelectedTab = tabControl1.TabPages[0];
     HtmlTemplate info = new HtmlTemplate();
     info.Status = this.checkBoxStatus.Checked ? 0 : 1;
     info.Subject = this.txtSubject.Text;
     info.Body = this.txtBody.Text;
     info.IsHTML = this.checkBoxIsHTML.Checked ? true : false;
     info.ShowName = this.txtShowName.Text;
     info.CreateTime = DateTime.Now.ToDateTime().ToDateTime();
     HtmlTemplateHelper.Insert(info);
     HtmlTemplateHelper.ClearCacheAll();
     frmTemplate_Load(sender, e);
 }
Beispiel #2
0
        private void mnuEdit_Click(object sender, EventArgs e)
        {
            SendSetting setting = SendSettingHelper.SelectByID(1);
            if (setting.IsNull() || setting.TemplateID.IsNull()) return;

            if (setting.TemplateID == lastID && !this.checkBoxStatus.Checked) {
                MessageBox.Show("发送邮件设置使用了此模板,该模板不能不可用", "系统提示");
                return;
            }

            tabControl1.SelectedTab = tabControl1.TabPages[0];
            if (currentIndex < 0 || lastID < 1) return;
            HtmlTemplate info = new HtmlTemplate();
            info.Subject = this.txtSubject.Text;
            info.Body = this.txtBody.Text;
            info.IsHTML = this.checkBoxIsHTML.Checked ? true : false;
            info.Status = this.checkBoxStatus.Checked ? 0 : 1;
            info.ShowName = this.txtShowName.Text;
            info.TemplateID = lastID;
            HtmlTemplateHelper.Update(info);
            dataGridView.Rows[currentIndex].Cells[1].Value = info.Subject;
            HtmlTemplateHelper.ClearCacheAll();
            MessageBox.Show("保存成功", "系统提示");
        }
Beispiel #3
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(); //清理数据
        }