tags:

views:

273

answers:

3

Hello...

How can I set the MailMessage´s body with a HTML file ?

Thanks

+1  A: 

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.

280Z28
+4  A: 

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...
    //...
}
CMS
A: 

What everyone else has said is correct. Here's another example for good measure:

http://www.4guysfromrolla.com/articles/080206-1.aspx

ryanulit