Gets the encapsulated e-mail message as a MailMessage object.
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.
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 To detect if the attachment is an e-mail message, the developer can use IsMessageInside property.
This sample loads the message from .EML file, extracts the encapsulated message, and displays all headers of the encapsulated message.
[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) // 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(); } }
[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) ' Load the message from file. Dim msg As New MailMessage msg.LoadMessage("C:\Docs\TestMail.eml") Dim attachedMsg As MailMessage = Nothing ' For every attachment... For Each attach As Attachment In msg.Attachments ' ...get the inner e-mail from the attachment. attachedMsg = attach.GetEncapsulatedMessage() ' When there is any inner e-mail... If Not attachedMsg Is Nothing Then ' ...show the header section of that e-mail. Console.WriteLine(attachedMsg.RawHeader) Console.WriteLine() End If Next
Attachment Class | MailBee.Mime Namespace | MailMessage | IsMessageInside