Mime MessageHtml Body Property
Get the html body of the message if it exists.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The html body if it exists; otherwise, .
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public string? HtmlBody { get; }Property Value
StringThe html body if it exists; otherwise, .
Implements
IMimeMessageHtmlBodyRemarks
Gets the HTML-formatted body of the message if it exists.
Example
C#
public static string GetMessageText (MimeMessage message)
{
// The TextBody and HtmlBody convenience properties find the text/plain and text/html
// bodies of the message, respectively, taking multipart/alternative and multipart/related
// structures into consideration. They return null if no suitable body exists.
if (message.TextBody != null)
return message.TextBody;
if (message.HtmlBody != null) {
// The message only has an HTML body. Convert it to plain text by stripping
// out the HTML markup.
var previewer = new HtmlTextPreviewer { MaximumPreviewLength = int.MaxValue };
return previewer.GetPreviewText (message.HtmlBody);
}
// GetTextBody() can be used to look for other text formats, such as text/enriched.
return message.GetTextBody (TextFormat.Enriched) ?? string.Empty;
}