예제 #1
0
        private void Email2(IQueryable <Person> q, int queuedBy, string fromAddr, string fromName, string subject,
                            string body)
        {
            //db.Log($"Email2 {subject}");
            var from = new MailAddress(fromAddr, fromName);

            q = from p in q
                where p.EmailAddress != null
                where p.EmailAddress != ""
                where (p.SendEmailAddress1 ?? true) || (p.SendEmailAddress2 ?? false)
                select p;
            var tag = db.PopulateSpecialTag(q, DbUtil.TagTypeId_Emailer);

            Util.IsInRoleEmailTest = TestEmail;
            var queueremail = db.People.Where(pp => pp.PeopleId == queuedBy).Select(pp => pp.EmailAddress).Single();

            Util.UserEmail = queueremail;
            db.SetCurrentOrgId(CurrentOrgId);

            var emailqueue = db.CreateQueue(queuedBy, from, subject, body, null, tag.Id, false);

            emailqueue.Transactional = Transactional;
            db.SendPeopleEmail(emailqueue.Id);
            //db.Log($"Email2 (queued) {subject}");
        }
예제 #2
0
        public void Email(string savedquery, int queuedBy, string fromaddr, string fromname, string subject, string body, bool transactional = false)
        {
            var from = new MailAddress(fromaddr, fromname);
            var qB   = Db.QueryBuilderClauses.FirstOrDefault(c => c.Description == savedquery && c.SavedBy == "public");

            if (qB == null)
            {
                return;
            }
            var q = Db.PeopleQuery(qB.QueryId);

            if (qB.ParentsOf)
            {
                q = Db.PersonQueryParents(q);
            }

            q = from p in q
                where p.EmailAddress != null
                where p.EmailAddress != ""
                where (p.SendEmailAddress1 ?? true) || (p.SendEmailAddress2 ?? false)
                select p;
            var tag        = Db.PopulateSpecialTag(q, DbUtil.TagTypeId_Emailer);
            var emailqueue = Db.CreateQueue(queuedBy, from, subject, body, null, tag.Id, false);

            Db.SendPeopleEmail(emailqueue.Id);
        }
예제 #3
0
        private void Email2(CMSDataContext db2, IQueryable <Person> q, int queuedBy, string fromAddr, string fromName, string subject,
                            string body)
        {
            var from = new MailAddress(fromAddr, fromName);

            q = from p in q
                where p.EmailAddress != null
                where p.EmailAddress != ""
                where (p.SendEmailAddress1 ?? true) || (p.SendEmailAddress2 ?? false)
                select p;
            var tag = db2.PopulateSpecialTag(q, DbUtil.TagTypeId_Emailer);

            Util.IsInRoleEmailTest = TestEmail;
            var queueremail = db2.People.Where(pp => pp.PeopleId == queuedBy).Select(pp => pp.EmailAddress).SingleOrDefault();

            if (!queueremail.HasValue())
            {
                throw new Exception("QueuedBy PeopleId not found in model.Email");
            }
            Util.UserEmail = queueremail;
            db2.SetCurrentOrgId(CurrentOrgId);

            var emailqueue = db2.CreateQueue(queuedBy, from, subject, body, null, tag.Id, false);

            emailqueue.Transactional = Transactional;
            db2.SendPeopleEmail(emailqueue.Id);
        }
예제 #4
0
파일: VolSubModel.cs 프로젝트: hkouns/bvcms
        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();
                }
            });
        }
예제 #5
0
        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 });
        }
예제 #6
0
        public ActionResult SendNow(int id)
        {
            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();
                }
            });
            return Redirect("/Manage/Emails/Details/" + id);
        }
예제 #7
0
파일: Email.cs 프로젝트: GSBCfamily/bvcms
        private void Email2(CMSDataContext db2, IQueryable<Person> q, int queuedBy, string fromAddr, string fromName, string subject,
            string body)
        {
            var from = new MailAddress(fromAddr, fromName);
            q = from p in q
                where p.EmailAddress != null
                where p.EmailAddress != ""
                where (p.SendEmailAddress1 ?? true) || (p.SendEmailAddress2 ?? false)
                select p;
            var tag = db2.PopulateSpecialTag(q, DbUtil.TagTypeId_Emailer);

            Util.IsInRoleEmailTest = TestEmail;
            var queueremail = db2.People.Where(pp => pp.PeopleId == queuedBy).Select(pp => pp.EmailAddress).SingleOrDefault();
            if(!queueremail.HasValue())
                throw new Exception("QueuedBy PeopleId not found in model.Email");
            Util.UserEmail = queueremail;
            db2.SetCurrentOrgId(CurrentOrgId);

            var emailqueue = db2.CreateQueue(queuedBy, from, subject, body, null, tag.Id, false);
            emailqueue.Transactional = Transactional;
            db2.SendPeopleEmail(emailqueue.Id);
        }