Example #1
0
        private void LoadSettings()
        {
            letterGuid = WebUtils.ParseGuidFromQueryString("letter", Guid.Empty);

            if (letterGuid != Guid.Empty)
            {
                letter = new Letter(letterGuid);
                if (letter.LetterGuid != Guid.Empty)
                {
                    letterInfo = new LetterInfo(letter.LetterInfoGuid);
                    if (letterInfo.SiteGuid != siteSettings.SiteGuid) { letter = null; }
                    if (!WebUser.IsInRoles(letterInfo.AvailableToRoles)) { letter = null; }
                    if ((!letterInfo.AllowArchiveView)&&(!WebUser.IsNewsletterAdmin))
                    {
                        letter = null;
                        unavailableReason = Resource.NewsletterArchivesNotAllowed;

                    }

                }
                else
                {
                    letter = null;
                }

            }

            AddClassToBody("administration");
            AddClassToBody("letterview");
        }
Example #2
0
        private void LoadSettings()
        {
            if (letterInfoGuid != Guid.Empty)
            {
                letterInfo = new LetterInfo(letterInfoGuid);
                if (letterInfo.LetterInfoGuid == Guid.Empty) { letterInfo = null; }
                if (letterInfo.SiteGuid != siteSettings.SiteGuid) { letterInfo = null; }
            }

            if (letterGuid != Guid.Empty)
            {
                letter = new Letter(letterGuid);
                if (letter.LetterGuid == Guid.Empty) { letter = null; }
                if (letter.LetterInfoGuid != letterInfoGuid) { letter = null; }
            }

            lnkSendLog.NavigateUrl = SiteRoot + "/eletter/SendLog.aspx?letter=" + letterGuid.ToString();

            lnkAdminMenu.Visible = WebUser.IsAdminOrContentAdmin;
            litLinkSeparator1.Visible = lnkAdminMenu.Visible;

            AddClassToBody("administration");
            AddClassToBody("lettersendprogress");
        }
Example #3
0
        private void SendLetter(
            SmtpSettings smtpSettings,
            LetterInfo letterInfo, 
            Letter letter, 
            LetterSubscriber subscriber)
        {
            // TODO: use multi part email with both html and plain text body
            // instead of this either or approach

            bool testMode = false;

            if (
                (ConfigurationManager.AppSettings["NewsletterTestMode"] != null)
                && (ConfigurationManager.AppSettings["NewsletterTestMode"] == "true")
                )
            {
                testMode = true;
            }

            LetterSendLog mailLog = new LetterSendLog();
            mailLog.EmailAddress = subscriber.EmailAddress;
            mailLog.LetterGuid = letter.LetterGuid;
            mailLog.UserGuid = subscriber.UserGuid;

            if (testMode)
            {
                Thread.Sleep(3000); // sleep 3 seconds per message to simulate
            }
            else
            {
                try
                {
                    if (subscriber.UseHtml)
                    {
                        Email.SendEmail(
                            smtpSettings,
                            letterInfo.FromAddress,
                            subscriber.EmailAddress,
                            string.Empty,
                            string.Empty,
                            letter.Subject,
                            ReplaceHtmlTokens(letter.HtmlBody, subscriber),
                            subscriber.UseHtml,
                            "Normal");
                    }
                    else
                    {
                        Email.SendEmail(
                            smtpSettings,
                            letterInfo.FromAddress,
                            subscriber.EmailAddress,
                            string.Empty,
                            string.Empty,
                            letter.Subject,
                            ReplaceTextTokens(letter.TextBody, subscriber),
                            subscriber.UseHtml,
                            "Normal");

                    }
                }
                catch (Exception ex)
                {
                    // TODO: catch more specific exception(s) figure out what ones can be thrown here
                    mailLog.ErrorOccurred = true;
                    mailLog.ErrorMessage = ex.ToString();
                    log.Error(ex);

                }
            }

            mailLog.Save();
        }
Example #4
0
        private void LoadSettings()
        {
            currentUser = SiteUtils.GetCurrentSiteUser();
            letterInfoGuid = WebUtils.ParseGuidFromQueryString("l", Guid.Empty);
            imageSiteRoot = WebUtils.GetSiteRoot();

            if (letterInfoGuid == Guid.Empty) return;

            letterInfo = new LetterInfo(letterInfoGuid);

            if (letterInfo.SiteGuid != siteSettings.SiteGuid)
            {
                letterInfo = null;
                letterInfoGuid = Guid.Empty;
            }

            letterGuid = WebUtils.ParseGuidFromQueryString("letter", Guid.Empty);

            if (letterGuid == Guid.Empty)
            {
                letter = new Letter();
            }
            else
            {
                letter = new Letter(letterGuid);

                if (letter.LetterInfoGuid != letterInfo.LetterInfoGuid)
                {
                    letterGuid = Guid.Empty;
                    letter = null;

                }
            }

            if (letter.SendCompleteUtc > DateTime.MinValue)
            {
                btnSave.Text = Resource.SaveNewsletterAsNewDraft;

                btnSendToList.Enabled = false;
                // once a letter has been sent only admin can delete it.
                btnDelete.Enabled = WebUser.IsAdmin;
            }

            //spnAdmin.Visible = WebUser.IsAdminOrContentAdmin;
            lnkAdminMenu.Visible = WebUser.IsAdminOrContentAdmin;
            litLinkSeparator1.Visible = lnkAdminMenu.Visible;

            AddClassToBody("administration");
            AddClassToBody("letteredit");
        }
Example #5
0
        private void ReportStatus()
        {
            TaskQueue task = new TaskQueue(this.taskGuid);

            if (totalSubscribersToSend > 0)
            {

                task.CompleteRatio = (subscribersSentSoFar / totalSubscribersToSend);
            }
            else
            {
                task.CompleteRatio = 1; //nothing to send so mark as complete
            }

            if (task.CompleteRatio >= 1)
            {
                task.Status = statusCompleteMessage;

                if(task.CompleteUTC == DateTime.MinValue)
                task.CompleteUTC = DateTime.UtcNow;

                Letter letter = new Letter(this.letterGuid);
                letter.TrackSendComplete(LetterSendLog.GetCount(letter.LetterGuid));

            }
            else
            {
                task.Status = string.Format(
                    CultureInfo.InvariantCulture,
                    statusRunningMessage,
                    subscribersSentSoFar,
                    totalSubscribersToSend);
            }

            task.LastStatusUpdateUTC = DateTime.UtcNow;
            task.Save();

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(updateFrequency);
        }
Example #6
0
        private void RunTask()
        {
            Letter letter = new Letter(this.letterGuid);
            if (letter.LetterGuid == Guid.Empty) return;
            if (letter.SendCompleteUtc > DateTime.MinValue) return;
            if (letter.SendClickedUtc == DateTime.MinValue) return;

            LetterInfo letterInfo = new LetterInfo(letter.LetterInfoGuid);

            // TODO: this could be a very large recordset if the kist is very large
            // might be better to get a page at a time instead of all at once.

            List<LetterSubscriber> subscribers
                = LetterSubscriber.GetSubscribersNotSentYet(
                letter.LetterGuid,
                letter.LetterInfoGuid);

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(updateFrequency);
            totalSubscribersToSend = subscribers.Count;

            if ((totalSubscribersToSend > 0) && (letter.SendStartedUtc == DateTime.MinValue))
            {
                letter.TrackSendStarted();
            }

            SmtpSettings smtpSettings = new SmtpSettings();
            smtpSettings.Password = password;
            smtpSettings.Port = port;
            smtpSettings.PreferredEncoding = preferredEncoding;
            smtpSettings.RequiresAuthentication = requiresAuthentication;
            smtpSettings.UseSsl = useSsl;
            smtpSettings.User = user;
            smtpSettings.Server = server;

            foreach (LetterSubscriber subscriber in subscribers)
            {
                SendLetter(smtpSettings, letterInfo, letter, subscriber);
                subscribersSentSoFar += 1;

                if (DateTime.UtcNow > nextStatusUpdateTime)
                    ReportStatus();

            }

            ReportStatus();
        }
Example #7
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByTextBody(Letter letter1, Letter letter2)
 {
     return letter1.TextBody.CompareTo(letter2.TextBody);
 }
Example #8
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByHtmlBody(Letter letter1, Letter letter2)
 {
     return(letter1.HtmlBody.CompareTo(letter2.HtmlBody));
 }
Example #9
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByLastModUtc(Letter letter1, Letter letter2)
 {
     return letter1.LastModUtc.CompareTo(letter2.LastModUtc);
 }
Example #10
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareBySendStartedUtc(Letter letter1, Letter letter2)
 {
     return letter1.SendStartedUtc.CompareTo(letter2.SendStartedUtc);
 }
Example #11
0
        private void LoadSettings()
        {
            //spnAdmin.Visible = WebUser.IsAdminOrContentAdmin;
            letterGuid = WebUtils.ParseGuidFromQueryString("letter", Guid.Empty);
            if (letterGuid == Guid.Empty) return;

            letter = new Letter(letterGuid);
            letterInfoGuid = letter.LetterInfoGuid;
            if (letterInfoGuid == Guid.Empty) return;

            letterInfo = new LetterInfo(letterInfoGuid);
            if (letterInfo.SiteGuid != siteSettings.SiteGuid)
            {
                letterInfo = null;
                letterInfoGuid = Guid.Empty;
                letter = null;
                letterGuid = Guid.Empty;
            }

            pageNumber = WebUtils.ParseInt32FromQueryString("pagenumber", 1);
            timeOffset = SiteUtils.GetUserTimeOffset();
            timeZone = SiteUtils.GetUserTimeZone();
            isAdmin = WebUser.IsAdmin;

            lnkAdminMenu.Visible = WebUser.IsAdminOrContentAdmin;
            litLinkSeparator1.Visible = lnkAdminMenu.Visible;

            AddClassToBody("administration");
            AddClassToBody("lettersendlog");
        }
Example #12
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByCreatedUtc(Letter letter1, Letter letter2)
 {
     return letter1.CreatedUtc.CompareTo(letter2.CreatedUtc);
 }
Example #13
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareBySendCount(Letter letter1, Letter letter2)
 {
     return(letter1.SendCount.CompareTo(letter2.SendCount));
 }
Example #14
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareBySendCompleteUtc(Letter letter1, Letter letter2)
 {
     return(letter1.SendCompleteUtc.CompareTo(letter2.SendCompleteUtc));
 }
Example #15
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByLastModUtc(Letter letter1, Letter letter2)
 {
     return(letter1.LastModUtc.CompareTo(letter2.LastModUtc));
 }
Example #16
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByCreatedUtc(Letter letter1, Letter letter2)
 {
     return(letter1.CreatedUtc.CompareTo(letter2.CreatedUtc));
 }
Example #17
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByTextBody(Letter letter1, Letter letter2)
 {
     return(letter1.TextBody.CompareTo(letter2.TextBody));
 }
Example #18
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareByHtmlBody(Letter letter1, Letter letter2)
 {
     return letter1.HtmlBody.CompareTo(letter2.HtmlBody);
 }
Example #19
0
        private void SaveAsNewDraft(Letter prevEdition)
        {
            letter = new Letter();

            letter.HtmlBody = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteRoot, imageSiteRoot, edContent.Text);
            letter.TextBody = txtPlainText.Text;
            letter.Subject = txtSubject.Text;
            letter.LastModBy = currentUser.UserGuid;
            if (letter.LetterGuid == Guid.Empty)
            {
                // new letter
                letter.LetterInfoGuid = letterInfoGuid;
                letter.CreatedBy = currentUser.UserGuid;
            }

            letter.Save();
            letterGuid = letter.LetterGuid;
        }
Example #20
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareBySendCount(Letter letter1, Letter letter2)
 {
     return letter1.SendCount.CompareTo(letter2.SendCount);
 }
Example #21
0
        private void RunTask()
        {
            Letter letter = new Letter(this.letterGuid);
            if (letter.LetterGuid == Guid.Empty)
            {
                log.Error("LetterSendTask letter not found so ending.");
                ReportStatus();
                return;
            }
            if (letter.SendCompleteUtc > DateTime.MinValue)
            {
                log.Error("LetterSendTask SendCompleteUtc already set so ending.");
                ReportStatus();
                return;
            }
            if (letter.SendClickedUtc == DateTime.MinValue)
            {
                log.Error("LetterSendTask SendClickedUtc has an invalid value so ending.");
                ReportStatus();
                return;
            }

            LetterInfo letterInfo = new LetterInfo(letter.LetterInfoGuid);
            SubscriberRepository subscriptions = new SubscriberRepository();

            if (WebConfigSettings.NewsletterTestMode)
            {
                testMode = true;
                log.Info("using NewsletterTestMode=true in config so no real emails will be sent for newsletter " + letterInfo.Title);
            }

            // TODO: this could be a very large recordset if the list is very large
            // might be better to get a page at a time instead of all at once.
            List<LetterSubscriber> subscribers
                = subscriptions.GetSubscribersNotSentYet(
                letter.LetterGuid,
                letter.LetterInfoGuid);

            nextStatusUpdateTime = DateTime.UtcNow.AddSeconds(reportingFrequency);
            totalSubscribersToSend = subscribers.Count;

            if ((totalSubscribersToSend > 0) && (letter.SendStartedUtc == DateTime.MinValue))
            {
                letter.TrackSendStarted();
            }

            if (totalSubscribersToSend < 100) { testSleepMilliseconds = 3000; }
            if (totalSubscribersToSend > 300) { testSleepMilliseconds = 500;}
            if (totalSubscribersToSend > 500) { testSleepMilliseconds = 100; }

            SmtpSettings smtpSettings = new SmtpSettings();
            smtpSettings.Password = password;
            smtpSettings.Port = port;
            smtpSettings.PreferredEncoding = preferredEncoding;
            smtpSettings.RequiresAuthentication = requiresAuthentication;
            smtpSettings.UseSsl = useSsl;
            smtpSettings.User = user;
            smtpSettings.Server = server;
            smtpSettings.AddBulkMailHeader = true;

            if (maxToSendPerMinute == 0) //not limit
            {
                foreach (LetterSubscriber subscriber in subscribers)
                {
                    SendLetter(smtpSettings, letterInfo, letter, subscriber);
                    subscribersSentSoFar += 1;

                    if (DateTime.UtcNow > nextStatusUpdateTime)
                        ReportStatus();

                }
            }
            else
            {
                int sentCount = 0;
                foreach (LetterSubscriber subscriber in subscribers)
                {
                    SendLetter(smtpSettings, letterInfo, letter, subscriber);
                    subscribersSentSoFar += 1;
                    sentCount += 1;

                    if (DateTime.UtcNow > nextStatusUpdateTime)
                        ReportStatus();

                    if (sentCount == maxToSendPerMinute)
                    {
                        ReportSleeping();
                        Thread.Sleep(60000); //sleep 1 minute
                        sentCount = 0;
                    }

                }
            }

            ReportStatus();
        }
Example #22
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareBySubject(Letter letter1, Letter letter2)
 {
     return letter1.Subject.CompareTo(letter2.Subject);
 }
Example #23
0
        private void SendLetter(
            SmtpSettings smtpSettings,
            LetterInfo letterInfo,
            Letter letter,
            LetterSubscriber subscriber)
        {
            // TODO: use multi part email with both html and plain text body
            // instead of this either or approach?

            LetterSendLog mailLog = new LetterSendLog();
            mailLog.EmailAddress = subscriber.EmailAddress;
            mailLog.LetterGuid = letter.LetterGuid;
            mailLog.UserGuid = subscriber.UserGuid;
            mailLog.SubscribeGuid = subscriber.SubscribeGuid;

            if (testMode)
            {
                Thread.Sleep(testSleepMilliseconds); // sleep 1 seconds per message to simulate

            }
            else
            {
                try
                {
                    if (subscriber.UseHtml)
                    {
                        Email.Send(
                            smtpSettings,
                            letterInfo.FromAddress.Coalesce(notificationFromEmail),
                            letterInfo.FromName.Coalesce(notificationFromAlias),
                            letterInfo.ReplyToAddress.Coalesce(notificationFromAlias),
                            subscriber.EmailAddress,
                            string.Empty,
                            string.Empty,
                            letter.Subject,
                            ReplaceHtmlTokens(letter.HtmlBody, subscriber, letterInfo),
                            subscriber.UseHtml,
                            "Normal");
                    }
                    else
                    {
                        Email.Send(
                            smtpSettings,
                            letterInfo.FromAddress.Coalesce(notificationFromEmail),
                            letterInfo.FromName.Coalesce(notificationFromAlias),
                            letterInfo.ReplyToAddress.Coalesce(notificationFromEmail),
                            subscriber.EmailAddress,
                            string.Empty,
                            string.Empty,
                            letter.Subject,
                            ReplaceTextTokens(letter.TextBody, subscriber, letterInfo),
                            subscriber.UseHtml,
                            "Normal");

                    }
                }
                catch (Exception ex)
                {
                    // TODO: catch more specific exception(s) figure out what ones can be thrown here
                    mailLog.ErrorOccurred = true;
                    mailLog.ErrorMessage = ex.ToString();
                    log.Error(ex);

                }
            }

            mailLog.Save();
        }
Example #24
0
        private static List<Letter> PopulateFromReader(IDataReader reader)
        {
            List<Letter> letterList = new List<Letter>();
            try
            {
                while (reader.Read())
                {
                    Letter letter = new Letter();
                    letter.letterGuid = new Guid(reader["LetterGuid"].ToString());
                    letter.letterInfoGuid = new Guid(reader["LetterInfoGuid"].ToString());
                    letter.subject = reader["Subject"].ToString();
                    letter.htmlBody = reader["HtmlBody"].ToString();
                    letter.textBody = reader["TextBody"].ToString();
                    letter.createdBy = new Guid(reader["CreatedBy"].ToString());
                    letter.createdUTC = Convert.ToDateTime(reader["CreatedUTC"]);
                    letter.lastModBy = new Guid(reader["LastModBy"].ToString());
                    letter.lastModUTC = Convert.ToDateTime(reader["LastModUTC"]);
                    letter.isApproved = Convert.ToBoolean(reader["IsApproved"]);
                    letter.approvedBy = new Guid(reader["ApprovedBy"].ToString());

                    if (reader["SendClickedUTC"] != DBNull.Value)
                        letter.sendClickedUTC = Convert.ToDateTime(reader["SendClickedUTC"]);

                    if (reader["SendStartedUTC"] != DBNull.Value)
                        letter.sendStartedUTC = Convert.ToDateTime(reader["SendStartedUTC"]);

                    if (reader["SendCompleteUTC"] != DBNull.Value)
                        letter.sendCompleteUTC = Convert.ToDateTime(reader["SendCompleteUTC"]);

                    if (reader["SendCount"] != DBNull.Value)
                        letter.sendCount = Convert.ToInt32(reader["SendCount"]);

                    letterList.Add(letter);
                }
            }
            finally
            {
                reader.Close();
            }

            return letterList;
        }
Example #25
0
 /// <summary>
 /// Compares 2 instances of Letter.
 /// </summary>
 public static int CompareBySubject(Letter letter1, Letter letter2)
 {
     return(letter1.Subject.CompareTo(letter2.Subject));
 }