Get attachment from the Embedded by using MapiMessage.FromProperties

Hi ,

I have problems with getting attachment from the embedded msg in the mail and pst file.
  • attachment from the embedded msg:
if we have a msg names “1.msg” which has an embedded msg “2.msg”, then the “2.msg” has an another embedded msg “3.msg” or attachment “3.doc”. So my problem is how to get the attchment of the “2.”

msg = MapiMessage.FromFile(“1.msg”);
if (msg.Attachments.Count>0)
{
GetAttachment(msg.Attachments)
}

private void GetAttachment(MapiAttachmentCollection sources)
{
for (int i = 0; i < sources.Count; i++)
{
if (sources[i].ObjectData!= null && sources[i].ObjectData.IsOutlookMessage)
{
MapiMessage m1 = MapiMessage.FromProperties(sources[i].ObjectData.Properties);
if (m1.Attachments.Count > 0) // here the count is always the zero, how can i get the attachment from the embedded msg?
GetAttachment(m1.Attachments);
}
}
}

  • Get attachment from the pst file.
PersonalStorage pst = PersonalStorage.FromFile(pstpath);
FolderInfo folderinfo = pst.RootFolder.GetSubFolder(“Inbox”);
int totalcount = folderinfo.ContentCount;
int count = (int)Math.Ceiling((double)totalcount / 50);
Console.WriteLine(“Count:”+totalcount);
MapiMessage msg = null;

for (int index = 0, i = 0; i < count; i++)
{
index = i * 50;
MessageInfoCollection messageInfoCollection = folderinfo.GetContents(index, 50);// max 50
foreach (MessageInfo messageInfo in messageInfoCollection)
{
try
{
msg = MapiMessage.FromProperties(messageInfo.Properties);
//msg = pst.ExtractMessage(messageInfo); it has the workaround. by using ExtractMessage
int i = msg.Attachments.Count;
msg.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}

}

Yeah, I have searched similar problem in the forum. And found this,

msg =MapiMessage.FromStream((new MemoryStream(sources[i].ObjectData.Data))) can provide me the attchment of the message.

By the way, does Apose.Mail support some function like outlook scanpst.exe ?

Many Thanks

Hi Yangc,

Thank you for writing to Aspose suppor team.

We are glad to find that you have got the appropriate code sample from our forum to retrieve the embedded attachment from an email. With respect to your query of ScanPst, I would like to share that Aspose.Email doesn’t provide any such facility of examining PSTs and report errors from these. If you have any additional query related to Aspose.Email, please feel free to write to us for further assistance.