Email displays br tags in text

Kentico User asked on March 28, 2016 16:57


I have a biz form and when that form is submitted it triggers a CMSModule. The module finds out 5 different alias paths and gets information from HTML fields which are part of a custom page type.

This is the following code

if (!string.IsNullOrEmpty(answer6NodeAliasPath))
                    node6 = tp.SelectSingleNode(CMS.SiteProvider.SiteContext.CurrentSiteName, answer6NodeAliasPath, "");
                    node6Value = node6.GetStringValue("AnswerExplanation", "");

                string[,] macros = new string[,] { 
                    { "text1", WebUtility.HtmlEncode(node1Value) }, 
                    { "text2", WebUtility.HtmlEncode(node2Value) },
                    { "text3", WebUtility.HtmlEncode(node3Value) },
                    { "text4", WebUtility.HtmlEncode(node4Value) },
                    { "text5", WebUtility.HtmlEncode(node5Value) },
                    { "text6", WebUtility.HtmlEncode(node6Value) }

                MacroResolver macroResolver = new MacroResolver();

                if (emailTemplate != null)
                    EmailMessage emailMessage = new EmailMessage();
                    emailMessage.EmailFormat = EmailFormatEnum.Html;
                    emailMessage.Recipients = emailFieldValue;
                    emailMessage.From = emailTemplate.TemplateFrom;
                    emailMessage.Subject = emailTemplate.TemplateSubject;
                    EmailSender.SendEmailWithTemplateText(CMS.SiteProvider.SiteContext.CurrentSiteName, emailMessage, emailTemplate, macroResolver, true);

I am using an HTML email template which is very basic right now


The value of text1 is HTML data with HTML tags. The tags are not getting rendered in the email. The email shows up as My organization has a strong service vision and values<br /> 1. You scored yourself: Agree<br />

Any ideas?

Thank you

Recent Answers

Anton Grekhovodov answered on March 28, 2016 19:25


You call WebUtility.HtmlEncode method which converts HTML string to HTML-encoded string, so you have incorrect data.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on March 30, 2016 12:32


Or you can add the encode parameter to a macro:


Best regards,
Jan Hermann

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.