Example: If the attachment is itself a message (.pst and .ost formats only)
If the attachment is itself a message, you can read it using GetAttachmentMessage(attachment) of the BaseReader class. See the example below.
//A pst file containing message that contains attached message in Inbox folder.
string pstFileLocation = @"C:\test\someone@smthng.pst";
using (IReader reader = ReaderFactory.GetReader(pstFileLocation))
{
Folder inboxFolder = reader.GetFolder(@"/Top of Outlook data file/Inbox");
IEnumerable<Message> msgs = reader.ReadMessages(inboxFolder);
foreach (Message msg in msgs)
{
//Display some of Message properties.
Console.WriteLine($"{msg.EntryID} / {msg.Subject} / {msg.From} / {msg.DeliveryTime}");
if (msg.HasAttachments)
{
foreach (Attachment attachment in msg.Attachments)
{
if (attachment.AttachMethod == AttachMethod.ATTACH_EMBEDDED_MSG)
{
Message attMsg = (reader as BaseReader).GetAttachmentMessage(attachment);
//Write a msg file to the file system.
using (FileStream fs = new FileStream($"{attachmentSaveFolderPath}{attachment.SafeAttachmentFileName}", FileMode.Create, FileAccess.Write, FileShare.None)) {
reader.WriteAttachment(attachment, fs);
}
}
}
}
}
}