public void Fill() { Miami.Substitute.Dal.Template template = new Miami.Substitute.Dal.Template(); template.LoadByPrimaryKey(TemplateId); TemplateNameLabel.Text = template.Header; TemplateText.Text = template.Text; DeleteButton.Enabled = TemplateText.Text.Length > 0; }
public void Send() { try { Miami.Substitute.Dal.Template template = new Miami.Substitute.Dal.Template(); DataRowView drv = template.LoadTemplateByName(type.ToString()); if (drv != null && drv["Text"].ToString().Length > 0) { MailAddressCollection ññTemp = cc; bool testMode = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseTestEmailAddress"]); if (testMode) { cc = new MailAddressCollection(); to = new MailAddressCollection(); to.Add(System.Configuration.ConfigurationManager.AppSettings["TestEmailAddress"]); } MailMessage myMail = new MailMessage(); myMail.From = from; foreach (MailAddress item in to) { myMail.To.Add(item); } foreach (MailAddress item in cc) { myMail.CC.Add(item); } myMail.Subject = Fill(drv["Header"].ToString()); myMail.Body = Fill(drv["Text"].ToString()); myMail.Priority = MailPriority.Normal; myMail.IsBodyHtml = true; Dal.MailLog mailLog = new Miami.Substitute.Dal.MailLog(); mailLog.AddNew(); mailLog.LocationId = LocationId; mailLog.MailFrom = myMail.From.Address; mailLog.MailTo = myMail.To.ToString(); if (ññTemp.Count > 0) { mailLog.MailTo += " , cc: " + ññTemp.ToString(); } mailLog.MailType = type.ToString(); mailLog.Subject = myMail.Subject; mailLog.SendDate = DateTime.Now; mailLog.Message = myMail.Body; mailLog.Save(); int countLogs = mailLog.GetAllMailLogByLocationId(LocationId).Count; if (countLogs > 1000) { mailLog.DeleteMailLog(LocationId, countLogs - 1000); } SmtpClient smtpClient = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SmtpServer"]); smtpClient.Send(myMail); } } catch { } }
protected void SaveButton_Click(object sender, EventArgs e) { if (TemplateId == 0) return; Miami.Substitute.Dal.Template template = new Miami.Substitute.Dal.Template(); template.LoadByPrimaryKey(TemplateId); template.Text = TemplateText.Text; template.Save(); if (Action != null) Action(sender, e); }
protected void DeleteButton_Click(object sender, EventArgs e) { if (TemplateId == 0) { return; } Miami.Substitute.Dal.Template template = new Miami.Substitute.Dal.Template(); template.LoadByPrimaryKey(TemplateId); template.Text = String.Empty; template.Save(); if (Action != null) { Action(sender, e); } }
public void Send() { try { Miami.Substitute.Dal.Template template = new Miami.Substitute.Dal.Template(); DataRowView drv = template.LoadTemplateByName(type.ToString()); if (drv != null && drv["Text"].ToString().Length > 0) { MailAddressCollection ññTemp = cc; bool testMode = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseTestEmailAddress"]); if (testMode) { cc = new MailAddressCollection(); to = new MailAddressCollection(); to.Add(System.Configuration.ConfigurationManager.AppSettings["TestEmailAddress"]); } MailMessage myMail = new MailMessage(); myMail.From = from; foreach (MailAddress item in to) myMail.To.Add(item); foreach (MailAddress item in cc) myMail.CC.Add(item); myMail.Subject = Fill(drv["Header"].ToString()); myMail.Body = Fill(drv["Text"].ToString()); myMail.Priority = MailPriority.Normal; myMail.IsBodyHtml = true; Dal.MailLog mailLog = new Miami.Substitute.Dal.MailLog(); mailLog.AddNew(); mailLog.LocationId = LocationId; mailLog.MailFrom = myMail.From.Address; mailLog.MailTo = myMail.To.ToString(); if (ññTemp.Count > 0) mailLog.MailTo += " , cc: " + ññTemp.ToString(); mailLog.MailType = type.ToString(); mailLog.Subject = myMail.Subject; mailLog.SendDate = DateTime.Now; mailLog.Message = myMail.Body; mailLog.Save(); int countLogs = mailLog.GetAllMailLogByLocationId(LocationId).Count; if (countLogs > 1000) mailLog.DeleteMailLog(LocationId, countLogs - 1000); SmtpClient smtpClient = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SmtpServer"]); smtpClient.Send(myMail); } } catch { } }