MailBee.NET Objects 3.1

MailMessage.IsBodyAvail Method 

Indicates if the body of the specified format is present in the message.

public bool IsBodyAvail(
   string bodyFormat,
   bool originalBodyOnly
);

Parameters

bodyFormat
The content type of the body to be searched (e.g. text/plain).
originalBodyOnly
Indicates if only the original parts of the message should be processed.

Return Value

true if the body of specified format is present in the message; otherwise, false.

Remarks

A message may contain original MIME parts (they had already been present in the existing message when it was parsed) and MIME parts added by MailBee (for instance, they may appear when the existing message gets parsed by MailBee and MailBee automatically creates plain-text part if only HTML part is available in the message).

To access text bodies of the message, you can use BodyPlainText, BodyHtmlText, and BodyParts properties.

To make the plain-text body be automatically created from the HTML body if the plain-text body is missing, set HtmlToPlainMode property to IfNoPlain value. See BodyPlainText and BodyHtmlText topics for more information.

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptionbodyFormat is a null reference (Nothing in Visual Basic).

Example

This sample loads the message from .EML file and checks if it has an XML body.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");
if (msg.IsBodyAvail("text/xml", false))
{
    Console.WriteLine("Message does contain XML body.");
}
else
{
    Console.WriteLine("Message does not contain XML body.");
}
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class)
Dim msg As New MailMessage
msg.LoadMessage("C:\Docs\TestMail.eml")
If msg.IsBodyAvail("text/html", False) Then
    Console.WriteLine("Message does contain XML body.")
Else
    Console.WriteLine("Message does not contain XML body.")
End If

See Also

MailMessage Class | MailBee.Mime Namespace | BodyParts | Parser