Hello...
How can I set the MailMessage´s body with a HTML file ?
Thanks
Hello...
How can I set the MailMessage´s body with a HTML file ?
Thanks
Here's a simple example. And here's one that includes an embedded image (as opposed to an img
link to a web source, which many email clients won't display).
Edit: You can of course read the html file with File.ReadAllText
, which you'd use as in the links.
Just set the MailMessage.BodyFormat property to MailFormat.Html, and then dump the contents of your html file to the MailMessage.Body property:
using (StreamReader reader = File.OpenText(htmlFilePath)) // Path to your
{ // HTML file
MailMessage myMail = new MailMessage();
myMail.From = "[email protected]";
myMail.To = "[email protected]";
myMail.Subject = "HTML Message";
myMail.BodyFormat = MailFormat.Html;
myMail.Body = reader.ReadToEnd(); // Load the content from your file...
//...
}
What everyone else has said is correct. Here's another example for good measure: