Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email sent still contains HTML tags.

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);
like image 786
Richard77 Avatar asked Nov 25 '25 10:11

Richard77


2 Answers

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;
like image 131
sr28 Avatar answered Nov 27 '25 22:11

sr28


Add mail.IsBodyHtml = true;

This will enable HTML formatting for the email.

like image 39
Jawad Avatar answered Nov 28 '25 00:11

Jawad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!