Web.Config:
<appSettings>
<add key="html1" value="This is <br /> HTML email"/>
</appSettings>
I'm trying to generate HTML formatted email. Prior to putting data in Web.Config I had both text and HTML emails formatted correctly.
In code-behind:
StringBuilder emailMessageString = new StringBuilder();
emailMessageString.Append(WebConfigurationManager.AppSettings["html1"].ToString());
Output in HTML email:
This is <br /> HTML email
Expected output in HTML email:
This is
HTML email
UPDATE - 02-19-2015
It looks like code I wrote to generate HTML email is not working correctly and had previously posted the code in this question (in my own answer). Can someone spot what I'm doing wrong as it looks like only the text emails are working:
Correct Syntax for Generating HTML Email using AlternateView
You do not need to decode again. This should solve it -
var body = new StringBuilder();
body.Append(WebConfigurationManager.AppSettings["html1"]);
Also, ensure that you set IsBodyHtml to true.
var message = new MailMessage();
message.IsBodyHtml = true;
Hello Brother you can use Server.HtmlDecode(string s)
see below code
StringBuilder emailMessageString = new StringBuilder();
emailMessageString.Append(Server.HtmlDecode(WebConfigurationManager.AppSettings["html1"].ToString()));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.