Пример #1
0
        private static void LogException(string site, int batchId, Email email, Exception e)
        {
            log.Error("Failed to insert the sent info item for: " + email.to, e);
            using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext())
            {
                SentInfo sentTo = dataContext.SentInfos.FirstOrDefault(sent => sent.batchId == batchId &&
                                                                       sent.subscriptionEmail == email.to &&
                                                                       sent.site == site);

                if (sentTo == null)
                {
                    sentTo = new SentInfo
                    {
                        batchId           = batchId,
                        lastSendDate      = DateTime.Now,
                        site              = site,
                        status            = "failed",
                        subscriptionEmail = email.to
                    };
                    dataContext.SentInfos.InsertOnSubmit(sentTo);
                }
                else
                {
                    sentTo.status = "failed";
                }

                dataContext.SubmitChanges();
            }
        }
Пример #2
0
        /// <summary>
        /// Resends the email.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <param name="email">The email.</param>
        /// <param name="batchId">The batch id.</param>
        /// <returns>true if successful / false if not</returns>
        public Boolean ResendEmail(string site, string email, int batchId)
        {
            try
            {
                string emailTemplateURL = null;
                string emailSubject     = null;
                using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext())
                {
                    SiteConfiguration siteConfiguration = dataContext.SiteConfigurations.FirstOrDefault(siteName => siteName.site == site);
                    emailTemplateURL = siteConfiguration.emailTemplateURL;
                    emailSubject     = siteConfiguration.siteName + " " + (ConfigurationManager.AppSettings["Email.Subject"] as String);
                }

                string messageBody = GetEmailBody(emailTemplateURL + "?batchId=" + batchId);

                EmailSender.Instance.SendEmail(email, FromAddress, messageBody, emailSubject, false, true);

                using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext())
                {
                    SentInfo sentInfo = dataContext.SentInfos.FirstOrDefault(info => info.site == site && info.subscriptionEmail == email && info.batchId == batchId);

                    sentInfo.lastSendDate = DateTime.Now;
                    sentInfo.status       = "resent";

                    dataContext.SubmitChanges();
                }

                return(true);
            }
            catch (Exception e)
            {
                log.Error("Unable to resend email from batch " + batchId + " for site " + site + " to email " + email, e);

                using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext())
                {
                    SentInfo sentInfo = dataContext.SentInfos.FirstOrDefault(info => info.site == site && info.subscriptionEmail == email && info.batchId == batchId);

                    sentInfo.status = "resend failed";

                    dataContext.SubmitChanges();
                }

                return(false);
            }
        }
Пример #3
0
        private static void SaveSentMailInformation(string site, int batchId, Email email)
        {
            try
            {
                using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext())
                {
                    SentInfo sentTo = new SentInfo
                    {
                        batchId           = batchId,
                        lastSendDate      = DateTime.Now,
                        site              = site,
                        status            = "sent",
                        subscriptionEmail = email.to
                    };

                    dataContext.SentInfos.InsertOnSubmit(sentTo);
                    dataContext.SubmitChanges();
                }
            }
            catch (Exception e)
            {
                LogException(site, batchId, email, e);
            }
        }
 private void detach_SentInfos(SentInfo entity)
 {
     this.SendPropertyChanging();
     entity.Subscription = null;
 }
 partial void DeleteSentInfo(SentInfo instance);
 partial void UpdateSentInfo(SentInfo instance);
 partial void InsertSentInfo(SentInfo instance);
 private void detach_SentInfos(SentInfo entity)
 {
     this.SendPropertyChanging();
     entity.Batch = null;
 }
 private void attach_SentInfos(SentInfo entity)
 {
     this.SendPropertyChanging();
     entity.Batch = this;
 }