How can I set the MailMessage's body with a HTML file ?
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... //... }
2.1m questions
2.1m answers
60 comments
57.0k users