示例#1
0
        public IEmail Create(Dictionary <string, string> replacements)
        {
            var siteRootContext = SitecoreContext?.GetRootItem <ISite_Root>();

            var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("_BaseEmail");

            if (htmlEmailTemplate == null)
            {
                return(null);
            }

            var siteRoot  = siteRootContext;
            var emailHtml = htmlEmailTemplate.Html;

            replacements.SetValue("#Environment#", SiteSettings.GetSetting("Env.Value", string.Empty));
            replacements.SetValue("#Logo_URL#", (siteRoot?.Email_Logo != null)
                    ? GetMediaURL(siteRoot.Email_Logo.MediaId.ToString())
                    : string.Empty);
            replacements.SetValue("#Date#", DateTime.Now.ToString("dddd, d MMMM yyyy"));
            replacements.SetValue("#RSS_Link_URL#", siteRoot?.RSS_Link.GetLink());
            replacements.SetValue("#RssLogo#", (siteRoot?.RSS_Logo != null)
                    ? GetMediaURL(siteRoot.RSS_Logo.MediaId.ToString())
                    : string.Empty);
            replacements.SetValue("#LinkedIn_Link_URL#", siteRoot?.LinkedIn_Link.GetLink());
            replacements.SetValue("#LinkedinLogo#", (siteRoot?.Linkedin_Logo != null)
                    ? GetMediaURL(siteRoot.Linkedin_Logo.MediaId.ToString())
                    : string.Empty);
            replacements.SetValue("#Twitter_Link_URL#", siteRoot?.Twitter_Link.GetLink());
            replacements.SetValue("#TwitterLogo#", (siteRoot?.Twitter_Logo != null)
                    ? GetMediaURL(siteRoot.Twitter_Logo.MediaId.ToString())
                    : string.Empty);
            replacements.SetValue("#Footer_Content#", GetValue(siteRoot?.Email_Footer));

            emailHtml = emailHtml.ReplacePatternCaseInsensitive(replacements);

            var email     = EmailFactory.Create();
            var emailFrom = GetValue(siteRoot?.Email_From_Address);

            email.From       = emailFrom;
            email.Body       = emailHtml;
            email.IsBodyHtml = true;

            return(email);
        }
示例#2
0
        public string CreateBody(ArticleStruct articleStruct, string emailTitle, string publication, WorkflowInfo oldWorkflow)
        {
            var    htmlEmailTemplate = HtmlEmailTemplateFactory.Create("Workflow");
            string siteRoot          = HttpContext.Current.Request.Url.Host;

            if (htmlEmailTemplate == null)
            {
                return(null);
            }

            var article = _articleUtil.GetArticleItemByNumber(articleStruct.ArticleNumber);

            var authorString = string.Empty;

            foreach (var eachAuthor in articleStruct.Authors)
            {
                authorString = eachAuthor.Name + ",";
            }
            var emailHtml    = htmlEmailTemplate.Html;
            var replacements = new Dictionary <string, string>();

            replacements["#Email_Title#"]   = emailTitle;
            replacements["#Article_Title#"] = string.IsNullOrEmpty(articleStruct.Title) ? article.Fields["Title"].Value : articleStruct.Title;
            replacements["#Publish_Date#"]  = articleStruct.WebPublicationDate.ToString();
            replacements["#word_url#"]      = GetWordURL(articleStruct);

            ArticleItem articleItem = _service.GetItem <ArticleItem>(article.ID.ToString());

            if (articleItem != null)
            {
                var preview = _articleUtil.GetPreviewInfo(articleItem);
                if (preview != null)
                {
                    replacements["#preview_url#"] = preview.PreviewUrl;
                }
            }

            replacements["#Authors#"]     = string.IsNullOrEmpty(authorString) ? "No authors selected" : authorString;
            replacements["#Publication#"] = publication;

            replacements["#show_notes#"]   = "Notes: ";
            replacements["#Body_Content#"] = articleStruct.NotificationText;
            if (articleStruct.NotificationText == "")
            {
                replacements["#show_notes#"]   = "";
                replacements["#Body_Content#"] = "";
            }

            replacements["#content_editor#"] = Sitecore.Context.User.Profile.FullName;
            replacements["#current_time#"]   = DateTime.Now.ToString();

            var oldState = _service.Database.WorkflowProvider.GetWorkflow(oldWorkflow.StateID);

            if (oldState != null)
            {
                //replacements["#old_state_image#"] = "https://" + siteRoot + oldState.Appearance.Icon;
                replacements["#old_state#"] = oldState.Appearance.DisplayName;
            }
            var newState = _service.Database.WorkflowProvider.GetWorkflow(articleStruct.CommandID.ToString());

            if (newState != null)
            {
                //replacements["#new_state_image#"] = "https://" + siteRoot + newState.Appearance.Icon;
                replacements["#new_state#"] = newState.Appearance.DisplayName;
            }


            List <WorkflowEvent> workflowHistory = GetWorkflowHistory(article);

            replacements["#history#"] = HistoryTableCreation(workflowHistory);
            var eHtml = emailHtml.ReplacePatternCaseInsensitive(replacements);

            return(eHtml);
        }
        public string GetEmailBody(string senderEmail, string senderName, string articleNumber, string message)
        {
            string emailHtml = string.Empty;

            try
            {
                var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("EmailFriend");

                if (htmlEmailTemplate == null)
                {
                    return(null);
                }

                var siteRoot = SiteRootContext.Item;
                emailHtml = htmlEmailTemplate.Html;
                var footerContent = GlobalService.GetItem <IEmail_Config>(Constants.ScripEmailConfig);
                var replacements  = new Dictionary <string, string>
                {
                    ["#Environment#"]       = SiteSettings.GetSetting("Env.Value", string.Empty),
                    ["#Date#"]              = DateTime.Now.ToString("dddd, d MMMM yyyy"),
                    ["#RSS_Link_URL#"]      = siteRoot?.RSS_Link.GetLink(),
                    ["#LinkedIn_Link_URL#"] = siteRoot?.LinkedIn_Link.GetLink(),
                    ["#Twitter_Link_URL#"]  = siteRoot?.Twitter_Link.GetLink(),
                    ["#sender_name#"]       = senderName,
                    ["#sender_email#"]      = senderEmail,
                    ["#Logo_URL#"]          = (siteRoot?.Email_Logo != null)
                                                                ? GetMediaURL(siteRoot.Email_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#RssLogo#"] = (siteRoot?.RSS_Logo != null)
                                                                ? GetMediaURL(siteRoot.RSS_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#LinkedinLogo#"] = (siteRoot?.Linkedin_Logo != null)
                                                                ? GetMediaURL(siteRoot.Linkedin_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#TwitterLogo#"] = (siteRoot?.Twitter_Logo != null)
                                                                ? GetMediaURL(siteRoot.Twitter_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#personal_message#"] = (!string.IsNullOrEmpty(message))
                                                                ? $"\"{message}\""
                                                                : string.Empty,
                    ["#Footer_Content#"] = GetValue(footerContent?.Email_A_Friend_Footer_Content)
                                           .ReplacePatternCaseInsensitive("#SENDER_EMAIL#", senderEmail),
                    ["#sender_name_message#"] = !string.IsNullOrEmpty(message)
                                                                ? TextTranslator.Translate("Search.Message").Replace("#SENDER_NAME#", senderName)
                                                                : string.Empty
                };

                // Article Body
                var article = GetArticle(articleNumber);
                replacements["#article_date#"]      = article?.Actual_Publish_Date.ToString("dd MMMM yyyy") ?? string.Empty;
                replacements["#article_mediatype#"] = article?.Media_Type?.Item_Name ?? string.Empty;
                replacements["#article_title#"]     = article?.Title ?? String.Empty;
                replacements["#article_titleURL#"]  = (article != null)
                                                ? $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}{article._Url}?utm_medium=email&utm_campaign=emailfriend"
                                                : string.Empty;
                replacements["#article_authorBy#"] = (article != null && article.Authors.Any())
                                                ? TextTranslator.Translate("Article.By")
                                                : string.Empty;
                replacements["#article_author#"] = (article != null && article.Authors.Any())
                                                ? string.Join(",", article.Authors.Select(a => $"{a.First_Name} {a.Last_Name}"))
                                                : string.Empty;
                replacements["#article_summary#"] = (article != null && !string.IsNullOrEmpty(article.Summary))
                                                ? ArticleService.GetArticleSummary(article)
                                                : string.Empty;

                emailHtml = emailHtml.ReplacePatternCaseInsensitive(replacements);
            }
            catch (Exception ex)
            {
                _logger.Warn($"Email failed to send: {senderEmail}:{senderName}:{articleNumber}:{message}", ex);
            }
            return(emailHtml);
        }