Reputation: 21661
I'm sending an email to people using a template. The problem is that all the tags are being shown.
<p>Hello,</p>
<p> Please, click the following link to change your password </p>
//...
<p> PLEASE DO NOT REPLY TO THIS MESSAGE</p>
The mail received is displaying exactly the original message with all the tags. Is there a way to make it look like
Here's my code:
string path = System.Web.HttpContext.Current.Server.MapPath("~/path/myTemplate.txt");
String body;
using (StreamReader sr = new StreamReader(path))
{
body = sr.ReadToEnd();
}
body = body.Replace("<%PasswordLink%>", pwdLink);
var mail = new MailMessage("from", "to");
mail.Subject = "Password Reset";
mail.Priority = MailPriority.High;
mail.Body = body;
var client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "123.45.67.89";
client.Send(mail);
Upvotes: 3
Views: 2725
Reputation: 5156
You need to state that the mail message is HTML. If your using System.Web.Mail.MailMessage then use:
mail.BodyFormat = MailFormat.Html;
If you're using System.Net.Mail.MailMessage then use:
mail.IsBodyHtml = true;
Upvotes: 6
Reputation: 91
I guess you have to define the mail body as HTML:
mail.IsBodyHtml = true;
Upvotes: 1
Reputation: 111
Add mail.IsBodyHtml = true;
This will enable HTML formatting for the email.
Upvotes: 1