0
votes

I set a macro for my html email template like so:

message = message.Replace("\n", "<br>"); //tried with and without
message = Server.HtmlEncode(message); //tried with and without
MacroContext.GlobalResolver.SetNamedSourceData("Message", message);

But the email just renders the <br> tag as text.

I am definitely receiving the html email and not the plain text one.

If I don't manipulate the text and leave it go through with the \n intact and check the email in the sent queue, it displays as it should!

How do I get the newlines to the email template?

2

2 Answers

1
votes

This is Example code that is sending the Email and works for me:

  var emailTemplate = EmailTemplateProvider.GetEmailTemplate(EmailName, SiteContext.CurrentSiteID);
            var message = "<br/>";
            MacroResolver resolver = MacroResolver.GetInstance();
            resolver.SetNamedSourceData("Message", message);

            EmailMessage message = new EmailMessage();
            message.From = resolver.ResolveMacros(emailTemplate.TemplateFrom);
            message.Recipients = user.Email;
            message.Body = resolver.ResolveMacros(emailTemplate.TemplateText);
            message.Subject = resolver.ResolveMacros(emailTemplate.TemplateSubject);

            EmailSender.SendEmail(SiteContext.CurrentSiteName, message, emailTemplate.TemplateName, resolver,
                false);

Macro in the Email Template:

{%Message%}
0
votes

Well the HtmlEncode will make your <br> look like text. At least you need to to reverse 1st and 2nd line.