MailMessageMakePlainBodyFromHtmlBody Method
Creates a plain text body from the existing HTML body of the message.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public bool MakePlainBodyFromHtmlBody()

Return Value

Type: Boolean
true if the plain-text body was successfully generated from the HTML body; false if the message did not have an HTML body.
Remarks

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.

Examples
This sample creates the HTML body of the message from .HTM file and converts it into the plain text body. Reading from stream and using MakePlainBodyFromHtmlBody is for demonstration purposes only. In real world apps, it's easier to use LoadBodyText(String, MessageBodyType, Encoding, ImportBodyOptions) method to load the file and MailMessage.Builder.HtmlToPlainMode property to enable automatic creating plain-text version of the HTML body.
// 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);
}
See Also