Beispiel #1
0
        private async Task <string> GetVerificationEmailHtml(string verifyUrl)
        {
            var getTemplateInput = new GetTemplateInput
            {
                TemplateType         = TemplateTypes.Alert,
                SimpleVariableValues = new Dictionary <string, string>
                {
                    { TemplateVariables.Heading, $"Verify your email" }
                },
                BodyParagraphs = new List <BodyParagraph>
                {
                    new BodyParagraph {
                        HtmlText = $"Hello, please click the button below to verify your email address. This is required before you can receive new album emails:"
                    },
                    new BodyParagraph {
                        HtmlText = "Verify", ButtonUrl = verifyUrl
                    },
                    new BodyParagraph {
                        HtmlText = $"Thanks for using New Albums via Email."
                    }
                }
            };

            var template = await _templateManager.GetHtmlEmailTemplate(getTemplateInput);

            return(template.ToString());
        }
        public async Task <StringBuilder> GetHtmlEmailTemplate(GetTemplateInput input)
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"NewAlbums.Emails.Templates.{input.TemplateType}.html"))
            {
                using (var memoryStream = new MemoryStream())
                {
                    await stream.CopyToAsync(memoryStream);

                    var bytes    = memoryStream.ToArray();
                    var template = new StringBuilder(Encoding.UTF8.GetString(bytes, 0, bytes.Length));

                    ReplaceVariables(ref template, input);
                    return(template);
                }
            }
        }
Beispiel #3
0
        private async Task <string> GetNotificationAlbumHtml(NotifySubscribersInput input, string unsubscribeArtistUrl, string unsubscribeAllUrl)
        {
            string albumImageWidth = "280";

            var getTemplateInput = new GetTemplateInput
            {
                TemplateType         = TemplateTypes.Alert,
                SimpleVariableValues = new Dictionary <string, string>
                {
                    { TemplateVariables.Heading, $"New album from {input.Artist.Name}" }
                },
                BodyParagraphs = new List <BodyParagraph>
                {
                    new BodyParagraph {
                        HtmlText = $"Good news, {input.Artist.Name} just released a new album: {HttpUtility.HtmlEncode(input.Album.Name)}."
                    },
                    new BodyParagraph {
                        HtmlText = $"<img alt=\"{HttpUtility.HtmlEncode(input.Album.Name)}\" src=\"{input.Album.Image.Url}\" width=\"{albumImageWidth}\" height=\"{albumImageWidth}\" />"
                    },
                    new BodyParagraph {
                        HtmlText = "Click Here to Listen", ButtonUrl = $"{Album.GetSpotifyUrl(input.Album.SpotifyId)}"
                    }
                },
                FooterLines = new List <FooterLine>
                {
                    new FooterLine {
                        HtmlText = _templateManager.GetEmailLink(unsubscribeArtistUrl, "Unsubscribe", null, "12px") + " from new albums for this artist."
                    },
                    new FooterLine {
                        HtmlText = _templateManager.GetEmailLink(unsubscribeAllUrl, "Unsubscribe", null, "12px") + " from all new albums from us."
                    }
                }
            };

            var template = await _templateManager.GetHtmlEmailTemplate(getTemplateInput);

            return(template.ToString());
        }
Beispiel #4
0
 public WorkFlowTemplateDto GetTemplate(GetTemplateInput input)
 {
     throw new NotImplementedException();
 }
        private void ReplaceVariables(ref StringBuilder template, GetTemplateInput input)
        {
            //Common variables
            string primaryColour       = _configuration[AppSettingKeys.Style.PrimaryColour];
            string textColourOnPrimary = _configuration[AppSettingKeys.Style.TextColourOnPrimary];

            template.Replace($"{{{TemplateVariables.PrimaryColour}}}", primaryColour);
            template.Replace($"{{{TemplateVariables.BackgroundColour}}}", _configuration[AppSettingKeys.Style.BackgroundColour]);
            template.Replace($"{{{TemplateVariables.FrontEndRootUrl}}}", _configuration[AppSettingKeys.App.FrontEndRootUrl]);

            //Other variables specific to this email
            foreach (var key in input.SimpleVariableValues.Keys)
            {
                template.Replace($"{{{key}}}", input.SimpleVariableValues[key]);
            }

            //Body
            var bodyHtml = new StringBuilder();

            foreach (var paragraph in input.BodyParagraphs)
            {
                bodyHtml.Append($"{EmailRowHtml}{BodyCellHtml}");

                if (String.IsNullOrWhiteSpace(paragraph.ButtonUrl))
                {
                    bodyHtml.Append($"{paragraph.HtmlText}");
                }
                else
                {
                    bodyHtml.Append($"<a href=\"{paragraph.ButtonUrl}\" target=\"_blank\" rel=\"noopener\" class=\"btn-primary\" style=\"font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; "
                                    + $"box-sizing: border-box; font-size: 14px; color: {textColourOnPrimary}; text-decoration: none; line-height: 2em; font-weight: bold; "
                                    + $"text-align: center; cursor: pointer; display: inline-block; border-radius: 5px; background-color: {primaryColour}; "
                                    + $"margin: 0; border-color: {primaryColour}; border-style: solid; border-width: 10px 20px;\">{paragraph.HtmlText}</a>");
                }

                bodyHtml.Append("</td></tr>");
            }

            template.Replace($"{{{TemplateVariables.Body}}}", bodyHtml.ToString());

            //Footer
            var footerHtml = new StringBuilder();

            //Append provided lines first
            foreach (var line in input.FooterLines)
            {
                footerHtml.Append($"{EmailRowHtml}{FooterCellHtml}{line.HtmlText}</td></tr>");
            }

            //Then append generic lines for all emails
            string frontEndRootUrl = _configuration[AppSettingKeys.App.FrontEndRootUrl];
            // string contactEmailAddress = _configuration[AppSettingKeys.App.ContactEmailAddress];
            string spotifyLogoUrl = frontEndRootUrl.EnsureEndsWith('/') + "images/spotify-logo-white.png";

            footerHtml.Append($"{EmailRowHtml}{FooterCellHtml}{GetEmailLink(frontEndRootUrl, frontEndRootUrl, null, "12px")}</td></tr>");
            // footerHtml.Append($"{EmailRowHtml}{FooterCellHtml}{GetEmailLink($"mailto:{contactEmailAddress}", contactEmailAddress, null, "12px")}</td></tr>");
            footerHtml.Append($"{EmailRowHtml}{FooterCellHtml}Artist and album content including cover art supplied by:</td></tr>");
            footerHtml.Append($"{EmailRowHtml}{FooterCellHtml}<img alt=\"Spotify logo\" src=\"{spotifyLogoUrl}\" width=\"80\" height=\"24\" style=\"width: 80px; height: 24px; margin: 0; outline: none;\" /></td></tr>");

            template.Replace($"{{{TemplateVariables.Footer}}}", footerHtml.ToString());
        }