Exemplo n.º 1
0
        public static void SendNewsletterTest(int newsletterID, int?newsletterDesignID, int newsletterFormatID, string email, string mailServer, string mailFrom, string approvalCode)
        {
            NewsletterDesign newsletterDesign =
                ((newsletterDesignID == null) ? null : NewsletterDesign.GetByID((int)newsletterDesignID));

            if (newsletterID <= 0)
            {
                throw new Exception("Newsletter Id must be greater than 0");
            }
            Newsletter newsletter = Newsletter.GetByID(newsletterID);

            string           subject = newsletter.Title;
            SubscriptionType type    = SubscriptionType.Html;          //default

            if (!string.IsNullOrEmpty(approvalCode))
            {
                switch (newsletterFormatID)
                {
                case 1:
                    subject = "Html Newsletter Approval: " + subject;
                    type    = SubscriptionType.Html;
                    break;

                case 2:
                    subject = "Text Newsletter Approval: " + subject;
                    type    = SubscriptionType.PlainText;
                    break;

                case 3:
                    subject = "Multipart Newsletter Approval: " + subject;
                    type    = SubscriptionType.MultiPart;
                    break;

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

            Queue <SubscriberInfo> subscriber = new Queue <SubscriberInfo>();

            string[] recipients = email.Split(',');
            foreach (string i in recipients)
            {
                subscriber.Enqueue(new SubscriberInfo(i, type));
            }

            Mailout mailout  = MailoutFromNewsletter(newsletter, newsletterDesign.NewsletterDesignID);
            string  body     = GetNewsletterHtml(mailout, true).Replace("[[EntityID]]", "");
            string  bodyText = GetNewsletterText(mailout).Replace("[[EntityID]]", "");
            AttachmentCollection attachments = null;
            EmailSender          es          = new EmailSender(subject, subscriber, mailFrom, mailServer, bodyText, body, attachments);

            es.EnableLogging = false;
            es.Send();
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method wraps the body of the newsletter in the desired design and replaces placeholder tags with dynamic content
        /// </summary>
        /// <param name="mailout">The Mailout containing the newsletter data to be sent</param>
        /// <param name="email">Whether this newsletter should be formatted for sending out via email (vs. web-only display)</param>
        /// <returns></returns>
        public static string GetNewsletterHtml(Mailout mailout, bool email)
        {
            string       body          = string.Empty;
            const string trackingImage = @"<img src=""[[ROOT]]newsletter-opened.aspx?entityId=[[EntityID]]&amp;mailoutId=[[MailoutID]]"" height=""1"" width=""1"" border=""0"" />";

            NewsletterDesign newsletterDesign = NewsletterDesign.GetByID(Convert.ToInt32(mailout.DesignID));

            if (newsletterDesign != null)
            {
                if (newsletterDesign.Path != null)
                {
                    body = EmailTemplateService.HtmlMessageBody("~/" + newsletterDesign.Path, new { FullCompanyName = Globals.Settings.CompanyName, FullPhysicalMailAddress = Settings.CustomPhysicalMailAddress });
                    //The final remove is necessary to get rid of the "Trouble viewing this email" stuff from the Newsletter frontend pages
                    if (!email)
                    {
                        body = body.Remove(body.IndexOf("[[Email Only]]"), body.IndexOf("[[End Email Only]]") - body.IndexOf("[[Email Only]]") + "[[End Email Only]]".Length);
                    }
                    else
                    {
                        body = body.Replace("[[Email Only]]", "")
                               .Replace("[[End Email Only]]", "") + trackingImage;
                    }
                }
                else if (newsletterDesign.Template != null)
                {
                    body = newsletterDesign.Template;
                }
                else
                {
                    throw new Exception("No design path or html for selected design");
                }
                body = InsertDynamicContent(mailout, body, mailout.Body);

                // For front-end display, remove per-subscriber replacement tags
                if (!email)
                {
                    body = body.Replace("[[EntityID]]", "");
                }
            }
            return(body.Replace("[[ROOT]]", Helpers.RootPath));
        }