public void SendPersonEmail(int id, int pid) { var sysFromEmail = Util.SysFromEmail; var emailqueue = EmailQueues.Single(eq => eq.Id == id); var emailqueueto = EmailQueueTos.Single(eq => eq.Id == id && eq.PeopleId == pid); var fromname = emailqueueto.EmailQueue.FromName; fromname = !fromname.HasValue() ? emailqueue.FromAddr : emailqueue.FromName.Replace("\"", ""); var from = Util.FirstAddress(emailqueue.FromAddr, fromname); try { var p = LoadPersonById(emailqueueto.PeopleId); var body = DoClickTracking(emailqueue); var m = new EmailReplacements(this, body, from); var text = m.DoReplacements(p, emailqueueto); var aa = m.ListAddresses; if (Setting("sendemail", "true") != "false") { if (aa.Count > 0) { Util.SendMsg(sysFromEmail, CmsHost, from, emailqueue.Subject, text, aa, emailqueue.Id, pid); } else { Util.SendMsg(sysFromEmail, CmsHost, from, "(no email address) " + emailqueue.Subject, "<p style='color:red'>You are receiving this because there is no email address for {0}({1}). You should probably contact them since they were probably expecting this information.</p>\n{2}".Fmt(p.Name, p.PeopleId, text), Util.ToMailAddressList(from), emailqueue.Id, pid); } emailqueueto.Sent = DateTime.Now; emailqueue.Sent = DateTime.Now; if (emailqueue.Redacted ?? false) { emailqueue.Body = "redacted"; } SubmitChanges(); } } catch (Exception ex) { Util.SendMsg(sysFromEmail, CmsHost, from, "sent emails - error", ex.ToString(), Util.ToMailAddressList(from), emailqueue.Id, null); throw; } }
public void SendPersonEmail(string CmsHost, int id, int pid) { var sysFromEmail = Util.SysFromEmail; var emailqueue = EmailQueues.Single(eq => eq.Id == id); var emailqueueto = EmailQueueTos.Single(eq => eq.Id == id && eq.PeopleId == pid); var fromname = emailqueue.FromName; if (!fromname.HasValue()) { fromname = emailqueue.FromAddr; } else { fromname = emailqueue.FromName.Replace("\"", ""); } var From = Util.FirstAddress(emailqueue.FromAddr, fromname); try { var p = LoadPersonById(emailqueueto.PeopleId); string text = emailqueue.Body; var aa = DoReplacements(ref text, CmsHost, p, emailqueueto); var qs = "OptOut/UnSubscribe/?enc=" + Util.EncryptForUrl("{0}|{1}".Fmt(emailqueueto.PeopleId, From.Address)); var url = Util.URLCombine(CmsHost, qs); var link = @"<a href=""{0}"">Unsubscribe</a>".Fmt(url); text = text.Replace("{unsubscribe}", link, ignoreCase: true); text = text.Replace("{Unsubscribe}", link, ignoreCase: true); if (aa.Count > 0) { text = text.Replace("{toemail}", aa[0].Address, ignoreCase: true); text = text.Replace("%7Btoemail%7D", aa[0].Address, ignoreCase: true); } text = text.Replace("{fromemail}", From.Address, ignoreCase: true); text = text.Replace("%7Bfromemail%7D", From.Address, ignoreCase: true); if (Setting("sendemail", "true") != "false") { if (aa.Count > 0) { Util.SendMsg(sysFromEmail, CmsHost, From, emailqueue.Subject, text, aa, emailqueue.Id, pid); } else { Util.SendMsg(sysFromEmail, CmsHost, From, "(no email address) " + emailqueue.Subject, "<p style='color:red'>You are receiving this because there is no email address for {0}({1}). You should probably contact them since they were probably expecting this information.</p>\n{2}".Fmt(p.Name, p.PeopleId, text), Util.ToMailAddressList(From), emailqueue.Id, pid); } emailqueueto.Sent = DateTime.Now; emailqueue.Sent = DateTime.Now; if (emailqueue.Redacted ?? false) { emailqueue.Body = "redacted"; } SubmitChanges(); } } catch (Exception ex) { Util.SendMsg(sysFromEmail, CmsHost, From, "sent emails - error", ex.ToString(), Util.ToMailAddressList(From), emailqueue.Id, null); throw ex; } }