public ActionResult Index(Guid id, int? templateID, bool? parents, string body, string subj, bool? ishtml, bool? ccparents, bool? nodups, int? orgid) { if (Util.SessionTimedOut()) return Redirect("/Errors/SessionTimeout.htm"); if (!body.HasValue()) body = TempData["body"] as string; if (!subj.HasValue() && templateID != 0) { if (templateID == null) return View("SelectTemplate", new EmailTemplatesModel { WantParents = parents ?? false, QueryId = id, }); DbUtil.LogActivity("Emailing people"); var m = new MassEmailer(id, parents, ccparents, nodups); m.Host = Util.Host; if (body.HasValue()) templateID = SaveDraft(null, null, 0, null, body); ViewBag.templateID = templateID; m.OrgId = orgid; return View("Compose", m); } // using no templates DbUtil.LogActivity("Emailing people"); var me = new MassEmailer(id, parents, ccparents, nodups); me.Host = Util.Host; if (body.HasValue()) me.Body = Server.UrlDecode(body); if (subj.HasValue()) me.Subject = Server.UrlDecode(subj); ViewData["oldemailer"] = "/EmailPeople.aspx?id=" + id + "&subj=" + subj + "&body=" + body + "&ishtml=" + ishtml + (parents == true ? "&parents=true" : ""); if (parents == true) ViewData["parentsof"] = "with ParentsOf option"; return View("Index", me); }
public ActionResult Index(int? id, int? templateID, bool? parents, string body, string subj, bool? ishtml) { if (!id.HasValue) return Content("no id"); if (Util.SessionTimedOut()) return Redirect("/Errors/SessionTimeout.htm"); if (!body.HasValue()) body = TempData["body"] as string; if(!subj.HasValue() && templateID != 0 && DbUtil.Db.Setting("UseEmailTemplates", "false") == "true" ) { if (templateID == null) return View("SelectTemplate", new EmailTemplatesModel() { wantparents = parents ?? false, queryid = id.Value}); else { DbUtil.LogActivity("Emailing people"); var m = new MassEmailer(id.Value, parents); m.CmsHost = DbUtil.Db.CmsHost; m.Host = Util.Host; ViewBag.templateID = templateID; return View("Compose", m); } } // using no templates DbUtil.LogActivity("Emailing people"); var me = new MassEmailer(id.Value, parents); me.CmsHost = DbUtil.Db.CmsHost; me.Host = Util.Host; if (body.HasValue()) me.Body = Server.UrlDecode(body); if (subj.HasValue()) me.Subject = Server.UrlDecode(subj); ViewData["oldemailer"] = "/EmailPeople.aspx?id=" + id + "&subj=" + subj + "&body=" + body + "&ishtml=" + ishtml + (parents == true ? "&parents=true" : ""); if (parents == true) ViewData["parentsof"] = "with ParentsOf option"; return View(me); }
public void SendEmails() { var tag = Db.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, Db.NextTagId); Db.ExecuteCommand("delete TagPerson where Id = {0}", tag.Id); Db.TagAll(pids, tag); var dt = new DateTime(ticks); foreach (var id in pids) { var vr = new SubRequest { AttendId = attend.AttendId, RequestorId = person.PeopleId, Requested = dt, SubstituteId = id, }; attend.SubRequests.Add(vr); } var qb = Db.ScratchPadCondition(); qb.Reset(Db); qb.AddNewClause(QueryType.HasMyTag, CompareType.Equal, "{0},temp".Fmt(tag.Id)); attend.Commitment = CmsData.Codes.AttendCommitmentCode.FindSub; qb.Save(DbUtil.Db); var reportlink = @"<a href=""{0}OnlineReg/VolSubReport/{1}/{2}/{3}"">Substitute Status Report</a>" .Fmt(Db.CmsHost, attend.AttendId, person.PeopleId, dt.Ticks); var list = Db.PeopleFromPidString(org.NotifyIds).ToList(); //list.Insert(0, person); Db.Email(person.FromEmail, list, "Volunteer Substitute Commitment for " + org.OrganizationName, @" <p>{0} has requested a substitute on {1:MMM d} at {1:h:mm tt}.</p> <blockquote> {2} </blockquote>".Fmt(person.Name, attend.MeetingDate, reportlink)); // Email subs var m = new MassEmailer(qb.Id, null); m.Subject = subject; m.Body = message; DbUtil.LogActivity("Emailing Vol Subs"); m.FromName = person.Name; m.FromAddress = person.FromEmail; var eqid = m.CreateQueue(transactional: true); string host = Util.Host; // save these from HttpContext to set again inside thread local storage var useremail = Util.UserEmail; var isinroleemailtest = HttpContext.Current.User.IsInRole("EmailTest"); TaskAlias.Factory.StartNew(() => { Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; try { var db = new CMSDataContext(Util.GetConnectionString(host)); db.Host = host; // set these again inside thread local storage Util.UserEmail = useremail; Util.IsInRoleEmailTest = isinroleemailtest; db.SendPeopleEmail(eqid); } catch (Exception ex) { var ex2 = new Exception("Emailing error for queueid " + eqid, ex); ErrorLog errorLog = ErrorLog.GetDefault(null); errorLog.Log(new Error(ex2)); var db = new CMSDataContext(Util.GetConnectionString(host)); db.Host = host; // set these again inside thread local storage Util.UserEmail = useremail; Util.IsInRoleEmailTest = isinroleemailtest; var equeue = db.EmailQueues.Single(ee => ee.Id == eqid); equeue.Error = ex.Message.Truncate(200); db.SubmitChanges(); } }); }
public ActionResult SaveDraft(MassEmailer m, int saveid, string name, int roleid) { var id = SaveDraft(saveid, name, roleid, m.Subject, m.Body); System.Diagnostics.Debug.Print("Template ID: " + id); ViewBag.parents = m.wantParents; ViewBag.templateID = id; return View("Compose", m); }
public ActionResult TestEmail(MassEmailer m) { m.Body = GetBody(m.Body); if (Util.SessionTimedOut()) { Session["massemailer"] = m; return Content("timeout"); } if (m.EmailFroms().Count(ef => ef.Value == m.FromAddress) == 0) return Json(new { error = "No email address to send from." }); m.FromName = m.EmailFroms().First(ef => ef.Value == m.FromAddress).Text; var from = Util.FirstAddress(m.FromAddress, m.FromName); var p = DbUtil.Db.LoadPersonById(Util.UserPeopleId.Value); try { ValidateEmailReplacementCodes(DbUtil.Db, m.Body, from); DbUtil.Db.CopySession(); DbUtil.Db.Email(from, p, null, m.Subject, m.Body, false); } catch (Exception ex) { return Json(new { error = ex.Message }); } return Content("Test email sent."); }
public ActionResult QueueEmails(MassEmailer m) { m.Body = GetBody(m.Body); if (!m.Subject.HasValue() || !m.Body.HasValue()) return Json(new { id = 0, error = "Both subject and body need some text." }); if (!User.IsInRole("Admin") && m.Body.Contains("{createaccount}", ignoreCase: true)) return Json(new { id = 0, error = "Only Admin can use {createaccount}." }); if (Util.SessionTimedOut()) { Session["massemailer"] = m; return Content("timeout"); } DbUtil.LogActivity("Emailing people"); if (m.EmailFroms().Count(ef => ef.Value == m.FromAddress) == 0) return Json(new { id = 0, error = "No email address to send from." }); m.FromName = m.EmailFroms().First(ef => ef.Value == m.FromAddress).Text; int id; try { var eq = m.CreateQueue(); if (eq == null) throw new Exception("No Emails to send (tag does not exist)"); id = eq.Id; // If there are additional recipients, add them to the queue if (m.AdditionalRecipients != null) { foreach (var pid in m.AdditionalRecipients) { // Protect against duplicate PeopleIDs ending up in the queue var q3 = from eqt in DbUtil.Db.EmailQueueTos where eqt.EmailQueue == eq where eqt.PeopleId == pid select eqt; if (q3.Any()) { continue; } eq.EmailQueueTos.Add(new EmailQueueTo { PeopleId = pid, OrgId = eq.SendFromOrgId.HasValue ? eq.SendFromOrgId : null, Guid = Guid.NewGuid(), }); } DbUtil.Db.SubmitChanges(); } if (eq.SendWhen.HasValue) return Json(new { id = 0, content = "Emails queued to be sent." }); } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); return Json(new { id = 0, error = ex.Message }); } var host = Util.Host; // save these from HttpContext to set again inside thread local storage var userEmail = Util.UserEmail; var isInRoleEmailTest = User.IsInRole("EmailTest"); try { ValidateEmailReplacementCodes(DbUtil.Db, m.Body, new MailAddress(m.FromAddress)); } catch (Exception ex) { return Json(new { error = ex.Message }); } System.Threading.Tasks.Task.Factory.StartNew(() => { Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; try { var db = DbUtil.Create(host); var cul = db.Setting("Culture", "en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cul); // set these again inside thread local storage Util.UserEmail = userEmail; Util.IsInRoleEmailTest = isInRoleEmailTest; db.SendPeopleEmail(id); } catch (Exception ex) { var ex2 = new Exception("Emailing error for queueid " + id, ex); var errorLog = ErrorLog.GetDefault(null); errorLog.Log(new Error(ex2)); var db = DbUtil.Create(host); var equeue = db.EmailQueues.Single(ee => ee.Id == id); equeue.Error = ex.Message.Truncate(200); db.SubmitChanges(); } }); return Json(new { id = id }); }
public ActionResult TestEmail(MassEmailer m) { if (Util.SessionTimedOut()) { Session["massemailer"] = m; return Content("timeout"); } if (m.EmailFroms().Count(ef => ef.Value == m.FromAddress) == 0) return Content("No email address to send from"); m.FromName = m.EmailFroms().First(ef => ef.Value == m.FromAddress).Text; var From = Util.FirstAddress(m.FromAddress, m.FromName); var p = DbUtil.Db.LoadPersonById(Util.UserPeopleId.Value); try { DbUtil.Db.Email(From, p, null, m.Subject, m.Body, false); } catch (Exception ex) { return Content("<h2>Error Email Sent</h2>" + ex.Message); } return Content("<h2>Test Email Sent</h2>"); }
public ActionResult SaveDraft(int tagId, bool wantParents, int saveid, string name, string subject, string body, int roleid) { Content content; if (saveid > 0) { content = DbUtil.ContentFromID(saveid); } else { content = new Content { Name = name.HasValue() ? name : "new draft " + DateTime.Now.FormatDateTm(), TypeID = ContentTypeCode.TypeSavedDraft, RoleID = roleid }; content.OwnerID = Util.UserId; } content.Title = subject; content.Body = body; content.DateCreated = DateTime.Now; if (saveid == 0) DbUtil.Db.Contents.InsertOnSubmit(content); DbUtil.Db.SubmitChanges(); var m = new MassEmailer { TagId = tagId, wantParents = wantParents, CmsHost = DbUtil.Db.CmsHost, Host = Util.Host, Subject = subject, }; System.Diagnostics.Debug.Print("Template ID: " + content.Id); ViewBag.parents = wantParents; ViewBag.templateID = content.Id; return View("Compose", m); }
public ActionResult QueueEmails(MassEmailer m) { if (!m.Subject.HasValue() || !m.Body.HasValue()) return Json(new { id = 0, content = "<h2>Both Subject and Body need some text</h2>" }); if (!User.IsInRole("Admin") && m.Body.Contains("{createaccount}")) return Json(new { id = 0, content = "<h2>Only Admin can use {createaccount}</h2>" }); if (Util.SessionTimedOut()) { Session["massemailer"] = m; return Content("timeout"); } DbUtil.LogActivity("Emailing people"); if (m.EmailFroms().Count(ef => ef.Value == m.FromAddress) == 0) return Json(new { id = 0, content = "No email address to send from" }); m.FromName = m.EmailFroms().First(ef => ef.Value == m.FromAddress).Text; int id; try { id = m.CreateQueue(); if (id == 0) throw new Exception("No Emails to send (tag does not exist)"); if (m.Schedule.HasValue) return Json(new { id = 0, content = "<h2>Emails Queued</h2>" }); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return Json(new { id = 0, content = "<h2>Error</h2><p>{0}</p>".Fmt(ex.Message) }); } string host = Util.Host; // save these from HttpContext to set again inside thread local storage var useremail = Util.UserEmail; var isinroleemailtest = User.IsInRole("EmailTest"); System.Threading.Tasks.Task.Factory.StartNew(() => { Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; try { var Db = new CMSDataContext(Util.GetConnectionString(host)); Db.Host = host; var cul = Db.Setting("Culture", "en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cul); // set these again inside thread local storage Util.UserEmail = useremail; Util.IsInRoleEmailTest = isinroleemailtest; Db.SendPeopleEmail(id); } catch (Exception ex) { var ex2 = new Exception("Emailing error for queueid " + id, ex); ErrorLog errorLog = ErrorLog.GetDefault(null); errorLog.Log(new Error(ex2)); var Db = new CMSDataContext(Util.GetConnectionString(host)); Db.Host = host; var equeue = Db.EmailQueues.Single(ee => ee.Id == id); equeue.Error = ex.Message.Truncate(200); Db.SubmitChanges(); } }); string keepdraft = Request["keepdraft"]; int saveid = Request["saveid"].ToInt(); System.Diagnostics.Debug.Print("Keep: " + keepdraft + " - Save ID: " + saveid); if (keepdraft != "on" && saveid > 0) DbUtil.ContentDeleteFromID(saveid); return Json(new { id = id }); }
public void SendEmails(int? additional) { var tag = Db.FetchOrCreateTag(Util.SessionId, Util.UserPeopleId, Db.NextTagId); Db.ExecuteCommand("delete TagPerson where Id = {0}", tag.Id); Db.TagAll(pids, tag); var dt = new DateTime(ticks); foreach (var id in pids) { var vr = new VolRequest { MeetingId = meeting.MeetingId, RequestorId = person.PeopleId, Requested = dt, VolunteerId = id }; meeting.VolRequests.Add(vr); } var qb = Db.ScratchPadCondition(); qb.Reset(); qb.AddNewClause(QueryType.HasMyTag, CompareType.Equal, $"{tag.Id},temp"); meeting.AddEditExtra(Db, "TotalVolunteersNeeded", ((additional ?? 0) + limit).ToString()); qb.Save(DbUtil.Db); var rurl = DbUtil.Db.ServerLink($"/OnlineReg/VolRequestReport/{meeting.MeetingId}/{person.PeopleId}/{dt.Ticks}"); var reportlink = $@"<a href=""{rurl}"">Volunteer Request Status Report</a>"; var list = Db.PeopleFromPidString(org.NotifyIds).ToList(); //list.Insert(0, person); Db.Email(person.FromEmail, list, "Volunteer Commitment for " + org.OrganizationName, $@" <p>{person.Name} has requested volunteers on {meeting.MeetingDate:MMM d} for {meeting.MeetingDate:h:mm tt}.</p> <blockquote> {reportlink} </blockquote>"); // Email subs var m = new MassEmailer(qb.Id); m.Subject = subject; m.Body = message; DbUtil.LogActivity("Emailing Vol Subs"); m.FromName = person.Name; m.FromAddress = person.FromEmail; var eqid = m.CreateQueue(true).Id; var host = Util.Host; // save these from HttpContext to set again inside thread local storage var useremail = Util.UserEmail; var isinroleemailtest = HttpContext.Current.User.IsInRole("EmailTest"); HostingEnvironment.QueueBackgroundWorkItem(ct => { try { var db = DbUtil.Create(host); // set these again inside thread local storage Util.UserEmail = useremail; Util.IsInRoleEmailTest = isinroleemailtest; db.SendPeopleEmail(eqid); } catch (Exception ex) { var ex2 = new Exception("Emailing error for queueid " + eqid, ex); var errorLog = ErrorLog.GetDefault(null); errorLog.Log(new Error(ex2)); var db = DbUtil.Create(host); // set these again inside thread local storage Util.UserEmail = useremail; Util.IsInRoleEmailTest = isinroleemailtest; var equeue = db.EmailQueues.Single(ee => ee.Id == eqid); equeue.Error = ex.Message.Truncate(200); db.SubmitChanges(); } }); }
public ActionResult Index(Guid id, int? templateID, bool? parents, string body, string subj, bool? ishtml, bool? ccparents, bool? nodups, int? orgid, int? personid, bool? recover, bool? onlyProspects, bool? membersAndProspects) { if (Util.SessionTimedOut()) return Redirect("/Errors/SessionTimeout.htm"); if (!body.HasValue()) body = TempData["body"] as string; if (!subj.HasValue() && templateID != 0) { if (templateID == null) return View("SelectTemplate", new EmailTemplatesModel { WantParents = parents ?? false, QueryId = id, }); DbUtil.LogActivity("Emailing people"); var m = new MassEmailer(id, parents, ccparents, nodups); m.Host = Util.Host; if (body.HasValue()) templateID = SaveDraft(null, null, 0, null, body); ViewBag.templateID = templateID; m.OrgId = orgid; m.guid = id; if (recover == true) m.recovery = true; return View("Compose", m); } // using no templates DbUtil.LogActivity("Emailing people"); var me = new MassEmailer(id, parents, ccparents, nodups); me.Host = Util.Host; // Unless UX-AllowMyDataUserEmails is true, CmsController.OnActionExecuting() will filter them if (!User.IsInRole("Access")) { if (templateID != 0 || (!personid.HasValue && !orgid.HasValue)) return Redirect($"/Person2/{Util.UserPeopleId}"); } if (personid.HasValue) { me.AdditionalRecipients = new List<int> {personid.Value}; var person = DbUtil.Db.LoadPersonById(personid.Value); ViewBag.ToName = person?.Name; } else if (orgid.HasValue) { var org = DbUtil.Db.LoadOrganizationById(orgid.Value); me.Recipients = GetRecipientsFromOrg(orgid.Value, onlyProspects, membersAndProspects); me.Count = me.Recipients.Count(); ViewBag.ToName = org?.OrganizationName; } if (body.HasValue()) me.Body = Server.UrlDecode(body); if (subj.HasValue()) me.Subject = Server.UrlDecode(subj); ViewData["oldemailer"] = "/EmailPeople.aspx?id=" + id + "&subj=" + subj + "&body=" + body + "&ishtml=" + ishtml + (parents == true ? "&parents=true" : ""); if (parents == true) ViewData["parentsof"] = "with ParentsOf option"; return View("Index", me); }
private static bool UsesGrammarly(MassEmailer m) { return m.Body.Contains("btn_grammarly"); }
private static bool TooLarge(MassEmailer m) { return m.Body.Contains("data:image") || m.Body.Length > 400000; }
public ActionResult QueueEmails(MassEmailer m) { m.Body = GetBody(m.Body); if (UsesGrammarly(m)) return Json(new { error = GrammarlyNotAllowed }); if (TooLarge(m)) return Json(new { error = TooLargeError }); if (!m.Subject.HasValue() || !m.Body.HasValue()) return Json(new { id = 0, error = "Both subject and body need some text." }); if (!User.IsInRole("Admin") && m.Body.Contains("{createaccount}", ignoreCase: true)) return Json(new { id = 0, error = "Only Admin can use {createaccount}." }); if (Util.SessionTimedOut()) { Session["massemailer"] = m; return Content("timeout"); } DbUtil.LogActivity("Emailing people"); if (m.EmailFroms().Count(ef => ef.Value == m.FromAddress) == 0) return Json(new { id = 0, error = "No email address to send from." }); m.FromName = m.EmailFroms().First(ef => ef.Value == m.FromAddress).Text; int id; try { var eq = m.CreateQueue(); if (eq == null) throw new Exception("No Emails to send (tag does not exist)"); id = eq.Id; // If there are additional recipients, add them to the queue if (m.AdditionalRecipients != null) { foreach (var pid in m.AdditionalRecipients) { // Protect against duplicate PeopleIDs ending up in the queue var q3 = from eqt in DbUtil.Db.EmailQueueTos where eqt.EmailQueue == eq where eqt.PeopleId == pid select eqt; if (q3.Any()) { continue; } eq.EmailQueueTos.Add(new EmailQueueTo { PeopleId = pid, OrgId = eq.SendFromOrgId, Guid = Guid.NewGuid(), }); } DbUtil.Db.SubmitChanges(); } if (eq.SendWhen.HasValue) return Json(new { id = 0, content = "Emails queued to be sent." }); } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); return Json(new { id = 0, error = ex.Message }); } var host = Util.Host; // save these from HttpContext to set again inside thread local storage var userEmail = Util.UserEmail; var isInRoleEmailTest = User.IsInRole("EmailTest"); var isMyDataUser = User.IsInRole("Access") == false; try { ValidateEmailReplacementCodes(DbUtil.Db, m.Body, new MailAddress(m.FromAddress)); } catch (Exception ex) { return Json(new { error = ex.Message }); } HostingEnvironment.QueueBackgroundWorkItem(ct => { try { var db = DbUtil.Create(host); var cul = db.Setting("Culture", "en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo(cul); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cul); // set these again inside thread local storage Util.UserEmail = userEmail; Util.IsInRoleEmailTest = isInRoleEmailTest; Util.IsMyDataUser = isMyDataUser; db.SendPeopleEmail(id); } catch (Exception ex) { var ex2 = new Exception($"Emailing error for queueid {id} on {host}\n{ex.Message}", ex); var cb = new SqlConnectionStringBuilder(Util.ConnectionString) {InitialCatalog = "ELMAH"}; var errorLog = new SqlErrorLog(cb.ConnectionString) {ApplicationName = "BVCMS"}; errorLog.Log(new Error(ex2)); var db = DbUtil.Create(host); var equeue = db.EmailQueues.Single(ee => ee.Id == id); equeue.Error = ex.Message.Truncate(200); db.SubmitChanges(); } }); return Json(new { id = id }); }