Ejemplo n.º 1
0
        public static bool ForwardNewsletter(int mailoutID, Guid entityID, string toEmail, string fromEmail, string toName, string fromName)
        {
            Mailout mailout = Mailout.GetByID(mailoutID);

            if (mailout == null)
            {
                throw new Exception("The requested mailout does not exist");
            }

            NewsletterSendingTypeFormat sendingFormat = Settings.NewsletterSendingType;

            SubscriptionType type;

            switch (sendingFormat)
            {
            case NewsletterSendingTypeFormat.HtmlAndText:                     // when forwarding, we don't ask for a preferred format, so default to HTML
            case NewsletterSendingTypeFormat.HtmlOnly:
                type = SubscriptionType.Html;
                break;

            case NewsletterSendingTypeFormat.TextOnly:
                type = SubscriptionType.PlainText;
                break;

            case NewsletterSendingTypeFormat.Multipart:
                type = SubscriptionType.MultiPart;
                break;

            default:
                throw new Exception("Newsletter Format " + sendingFormat + " not defined.");
            }

            SubscriberInfo recipient = new SubscriberInfo(toEmail, type);

            String forwardPreambleText = "This newsletter was forwarded to you by " + fromName + " (" + fromEmail + ")\n";
            String forwardPreambleHtml = "<p>" + forwardPreambleText + "</p>";

            string body     = forwardPreambleHtml + GetNewsletterHtml(mailout, true).Replace("[[EntityID]]", "");
            string bodyText = forwardPreambleText + GetNewsletterText(mailout);
            string subject  = "FW: " + mailout.Title;

            if (SendSingleEmail(recipient, Settings.SenderEmail, subject, body, bodyText))
            {
                Subscriber subscriberEntity = Subscriber.GetSubscriberByEntityID(entityID);
                if (subscriberEntity != null)
                {
                    NewsletterAction.CreateForwardAction(subscriberEntity, mailoutID, toEmail);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send a Newsletter to a collection of mailing lists, or resend a previously sent Mailout to its collection of mailing lists
        /// </summary>
        /// <param name="newsletterId">The ID of the Newsletter to send</param>
        /// <param name="existingMailoutId">The ID of an existing Mailout to resend</param>
        /// <param name="designId">The ID of the design to wrap the newsletter content</param>
        /// <param name="mailingLists">Collection of mailing lists to send the mailout to</param>
        /// <param name="notSentSubscribers">Collection of subscribers who had invalid email addresses</param>
        /// <returns>True if at least one subscriber was sent the newsletter, false otherwise</returns>
        public static bool SendNewsletter(int?newsletterId, int?existingMailoutId, int designId, List <MailingList> mailingLists, out List <MailingListSubscriber> notSentSubscribers)
        {
            notSentSubscribers = new List <MailingListSubscriber>();

            Mailout mailout;

            if (existingMailoutId.HasValue)
            {
                mailout = Mailout.GetByID(existingMailoutId.Value);
            }
            else if (newsletterId.HasValue)
            {
                Newsletter newsletter = Newsletter.GetByID(newsletterId.Value);
                mailout = SaveNewMailoutForNewsletter(newsletter, mailingLists, designId);
            }
            else
            {
                return(false);
            }

            String htmlBodyWithDesign = GetNewsletterHtml(mailout, true);
            String textBody           = GetNewsletterText(mailout);

            List <int> mailingListIds = mailingLists.Select(ml => ml.MailingListID).ToList();

            Queue <SubscriberInfo> uniqueSubscribers = SubscriberInfo.GetMailingListSubscribersWithEmailsByListOfMailingListIDs(mailingListIds, existingMailoutId);

            if (uniqueSubscribers.Count > 0)
            {
                EmailSender es = new EmailSender(
                    mailout.Title,
                    uniqueSubscribers,
                    Settings.SenderEmail,
                    Settings.MailServer,
                    textBody,
                    htmlBodyWithDesign
                    , null);
                es.IPAddress      = HttpContext.Current.Request.UserHostAddress;
                es.MailoutID      = mailout.MailoutID;
                es.MailingListIDs = mailingListIds;
                es.Send();
                EmailSender.SendEmailJobs.Add(es);

                return(true);
            }
            return(false);
        }