MailMessageMakePlainBodyFromHtmlBody Method |
Namespace: MailBee.Mime
This method overwrites the original value of BodyPlainText property if any. BodyHtmlText is left intact (i.e. this method does not replace HTML body with plain-text body, it rather adds alternative plain-text version of the HTML body to the message).
To make plain-text body be generated automatically when the message contains only HTML body, set msg.Builder.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain prior to sending the message (assuming msg is MailMessage instance).
If you are parsing an existing message (received from the mail server, loaded from file, etc) rather than composing a new one, set msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain instead.
// To use the code below, import these namespaces at the top of your code. using System.IO; using MailBee; using MailBee.Mime; // The actual code (put it into a method of your class). using (StreamReader sr = new StreamReader(@"C:\Temp\doc.htm")) { MailMessage msg = new MailMessage(); msg.BodyHtmlText = sr.ReadToEnd(); msg.MakePlainBodyFromHtmlBody(); Console.WriteLine(msg.BodyPlainText); }