public IEmail Create(INewUser newUser) { if (newUser == null) { return(null); } var email = EmailFactory.Create(); if (email == null) { return(null); } var siteRoot = SiteRootContext.Item; var emailTo = newUser.Username; var replacements = new Dictionary <string, string>(); replacements["#Email#"] = emailTo; replacements["#Envrionment#"] = SiteSettings.GetSetting("Env.Value", string.Empty); replacements["#Page_Type#"] = "registration-successful-email-in-inbox"; replacements["#Body_Content#"] = GetValue(siteRoot?.Registration_Email_Body) .ReplacePatternCaseInsensitive("#First_Name#", newUser.FirstName) .ReplacePatternCaseInsensitive("#Last_Name#", newUser.LastName); email.Body = email.Body.ReplacePatternCaseInsensitive(replacements); var emailSubject = GetValue(siteRoot?.Registration_Email_Subject); email.To = emailTo; email.Subject = emailSubject; return(email); }
public string GetEmailBody(string senderEmail, string senderName, string articleNumber, string message, string companyName, string phoneNumber) { string emailHtml = string.Empty; try { var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("EmailAnalyst"); 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, ["#company_name#"] = companyName, ["#phone_number#"] = phoneNumber, ["#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 }; emailHtml = emailHtml.ReplacePatternCaseInsensitive(replacements); } catch (Exception ex) { _logger.Warn($"Email failed to send: {senderEmail}:{senderName}:{articleNumber}:{message}", ex); } return(emailHtml); }
public IEmail Create(IUserResetPassword userResetPassword) { var siteRootContext = SitecoreContext?.GetRootItem <ISite_Root>(); if (userResetPassword == null) { return(null); } var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("ResetPassword"); if (htmlEmailTemplate == null) { return(null); } var email = EmailFactory.Create(); var siteRoot = siteRootContext; var resetPasswordHtml = htmlEmailTemplate.Html; var userProfile = FindUserProfile.Find(userResetPassword.Username); var emailTo = userResetPassword.Username; var resetPasswordReplacements = new Dictionary <string, string>(); resetPasswordReplacements["#Reset_Link_URL#"] = UrlFactory.Create(userResetPassword); resetPasswordReplacements["#Reset_Link_Text#"] = GetValue(siteRoot?.Reset_Password_Email_Link_Text, TextTranslator.Translate("Authentication.ResetPassword.Email.ResetLink")); resetPasswordReplacements["#Body_Content#"] = GetValue(siteRoot?.Reset_Password_Email_Body); resetPasswordReplacements["#Support_Text#"] = GetValue(siteRoot?.Customer_Support_Text); resetPasswordHtml = resetPasswordHtml.ReplacePatternCaseInsensitive(resetPasswordReplacements); var baseReplacements = new Dictionary <string, string>(); baseReplacements["#Body_Content#"] = resetPasswordHtml; baseReplacements["#Email#"] = emailTo; baseReplacements["#Envrionment#"] = SiteSettings.GetSetting("Env.Value", string.Empty); baseReplacements["#Page_Type#"] = "reset-password-email-in-inbox"; if (userProfile != null) { baseReplacements["#First_Name#"] = userProfile.FirstName; baseReplacements["#Last_Name#"] = userProfile.LastName; baseReplacements["#UserName#"] = userProfile.Email; } email.Body = email.Body.ReplacePatternCaseInsensitive(baseReplacements); email.To = emailTo; email.Subject = GetValue(siteRoot?.Reset_Password_Email_Subject); return(email); }
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); }
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); }