Beispiel #1
0
        /// <summary>
        /// Creates a mail info object based on information on a page.
        /// </summary>
        /// <returns></returns>
        public virtual MailInformation GetMailInformation(PageData mailPage)
        {
            // Get Meta Information
            MailInformation mailInfo = GetMailMetaData(mailPage);

            // Get the two body versions
            string mailBody = GetPageHtml(mailPage);

            string hostUrl = GetSiteUrl(mailPage);

            mailInfo.BodyHtml = RewriteUrls(mailBody, hostUrl);

            mailInfo.BodyText = QuickCleanMailText(GetPageText(mailPage));

            // Let page add custom properties
            IPopulateCustomProperties customPropertiesProvider = mailPage as IPopulateCustomProperties;

            if (customPropertiesProvider != null)
            {
                // Let page populate the custom properties collection
                customPropertiesProvider.AddCustomProperties(mailInfo.CustomProperties);
            }

            return(mailInfo);
        }
        /// <summary>
        /// Populates needed mail information before sending. Will also check
        /// for Mailgun specific properties
        /// </summary>
        /// <remarks>
        /// Note! Mailgun validate campaign codes, and if the campaign does
        /// not exist, it will be ignored (the email will still be sent)
        /// Note! Tags are limited to a count of 200
        /// </remarks>
        /// <param name="mailPage"></param>
        /// <returns></returns>
        public override MailInformation GetMailInformation(PageData mailPage)
        {
            MailInformation mailInformation = base.GetMailInformation(mailPage);

            IPopulateCustomProperties customPropertiesProvider = mailPage as IPopulateCustomProperties;

            if (customPropertiesProvider == null)
            {
                // The base class will add custom properties if the page type
                // implements that - if NOT, we'll try to add them ourselves
                // by looking for special property names relevant to Mailgun
                var campaign = mailPage[MAILGUN_CAMPAIGN_PROPERTYNAME];
                if (campaign != null)
                {
                    mailInformation.Utm.Campaign = campaign.ToString();
                }

                // Since the Utm Campaign can be set independently, we check if it
                // is set, and use it as a Mailgun campaign too
                if (string.IsNullOrEmpty(mailInformation.Utm.Campaign) == false)
                {
                    mailInformation.CustomProperties.Add("o:campaign", mailInformation.Utm.Campaign);
                }


                if (mailPage[MAILGUN_TAG_PROPERTYNAME] != null)
                {
                    mailInformation.CustomProperties.Add("o:tag", mailPage[MAILGUN_TAG_PROPERTYNAME]);
                }
            }
            return(mailInformation);
        }