AttachmentGetEncapsulatedMessage Method
Gets the encapsulated e-mail message as a MailMessage object.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public MailMessage GetEncapsulatedMessage()

Return Value

Type: MailMessage
A MailMessage object containing the encapsulated e-mail message, or a null reference (Nothing in Visual Basic) if the attachment is not an e-mail message.
Remarks
This method extracts the encapsulated e-mail message from the attachment content, and represents it as a MailMessage object for any further use. The extracted message can then be easily examined, resent, replied, saved to disk, or processed in any other way.
Note Note
To detect if the attachment is an e-mail message, the developer can use IsMessageInside property.
Examples
This sample loads the message from .EML file, extracts the encapsulated message, and displays all headers of the encapsulated message.
// 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)

// Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");

MailMessage attachedMsg = null;

// For every attachment...
foreach (Attachment attach in msg.Attachments)
{
    // ...get the inner e-mail from the attachment.
    attachedMsg = attach.GetEncapsulatedMessage();

    // When there is any inner e-mail...
    if (attachedMsg != null)
    {
        // ...show the header section of that e-mail.
        Console.WriteLine(attachedMsg.RawHeader);
        Console.WriteLine();
    }
}
See Also