The attached msg file has four attachments.
When I open the msg file in a MailMessage object, and then debug inside Visual Studio, the msg.Headers array contains From, Subject, MessageID, Date and To fields. But there is no Attachments field.
And if I save XPS from the msg, there is no attachments line in the email header.
Is this a bug in apose.email? Is there a workaround?
Hi Thomas,
Thank you for contacting Aspose Support team.
Please use the following code sample that writes the attachments information to output XPS. If you face any other issue, please let us know for further assistance in this regard.
Sample Code:
MailMessage msg = MailMessage.Load(“767259\Message With Attachments.msg”, new MsgLoadOptions());
MailPrinter msgPrinter = new MailPrinter();
msgPrinter.FormattingFlags = MessageFormattingFlags.MailInfo | MessageFormattingFlags.Attachments;
// Call Print() method
msgPrinter.Print(msg, “767259\out.xps”, PrintFormat.XPS);
Hi Kashif,
The code we use to generate XPS from MSG is based on Tahir Manzoor’s [answer](https://forum.aspose.com/t/39203)
to a question I posted on this forum. Tahir’s code does the conversion in two steps - MSG to DOC then DOC to XPS.
This two-step code replaces the code I had been using, which was used MailPrinter to generate the XPS. But using MailPrinter the XPS formatting was wrong.
Using the two-step code, what extra flags should I use to get the generated XPS to have the Attachments line too? We cannot use MailPrinter because it doesn’t format XPS correctly.
Hi Brian,
Thank you for sharing additional details.
Could you please try the following code sample with the latest versions of Aspose.Email for .NET and Aspose.Words for .NET? We have used it to convert your sample file to XPS and the attachments line is visible in the output as you can see in the attached XPS file. Please try it at your end and let us know your feedback.
Sample Code:
MailMessage msg = MailMessage.Load(“768169\Message With Attachments.msg”, new MsgLoadOptions());
msg.Save(“768169\out.mhtml”, Aspose.Email.Mail.SaveOptions.DefaultMhtml);
Aspose.Words.Document doc = new Aspose.Words.Document(“768169\out.mhtml”);
doc.Save(“768169\out.xps”, Aspose.Words.SaveFormat.Xps);
Hi Kashif,
Thank you for the prompt reply. I can confirm that the supplied code produced XPS with the required Attachments: line.
Hi Brian,
You are welcome and please feel free to write to us if you have any further query in this regard.