This is the code we use:
Aspose.Email.License license = new Aspose.Email.License();
license.SetLicense(@"Q:\Install\Ontwikkeling\Componenten\Aspose Total for .NET\Aspose.Total.lic");
MailMessage theMessage = MailMessage.Load(@"D:\Temp\Aspose\Geen Onderwerp-135232524.eml");
foreach (Attachment attachment in theMessage.Attachments)
{
string filename = string.Join("_", attachment.Name.Split(Path.GetInvalidFileNameChars()));
if (attachment.ContentType.MediaType.Equals("message/rfc822", StringComparison.OrdinalIgnoreCase))
{
if (!Path.GetExtension(filename).Equals(".msg", StringComparison.OrdinalIgnoreCase))
{
filename += ".msg";
}
}
filename = Path.Combine(@"D:\Temp\Aspose\Output", filename);
if (attachment.ContentType.MediaType.Equals("message/rfc822", StringComparison.OrdinalIgnoreCase))
{
MemoryStream ms = new MemoryStream();
attachment.Save(ms);
MailMessage attMsg = MailMessage.Load(ms);
SaveOptions options = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode);
attMsg.Save(filename, options);
}
else
{
attachment.Save(filename);
}
}