Hi
We have been using Aspose.Email product to catch the mail on Exchange environment and save that mail in .MSG format. Recently we have been facing an issue where if user send any TNEF mail then Aspose is throwing an excpetion
stating that :“Properties should not be empty”.
We would like to know how the usage of LoadFromTnef() API. Any code example where LoadFromTnef() has been used will do the trick.
Thanks
Abhijit
Hi Abhijit,
Thank you for contacting Aspose Support.
Please give a try to he following sample code which loads an EML having Tnef MSG attachment. This attached MSG is loaded using LoadFromTnef() and saved on disc.
MailMessage sourceMsg = MailMessage.Load(@“Sample.eml”, FileCompatibilityMode.PreserveTnefAttachments);
MapiMessage orig = MapiMessage.LoadFromTnef(sourceMsg.Attachments[0].ContentStream);
orig.Save(@“TestTnef.msg”);
If this piece of code does not fulfill your requirement, please send us the sample file for re-producing the issue here for analysis and providing the solution.
Hi Kashif,
Thank you for the quick response.
I have been using the similar approach but the only difference is … instead of using the the .eml file in Load() API I have been using mailStream object. I am getting the mailStream object by using GetMimeReadStream() API on Microsoft.Exchange.Data.Transport.MailItem object.
When I am using the mailStream object in Load() API, it successfully loads the mailStream object in the MailMessage object but after that when I am calling the LoadFromTnef() API I am getting an exception.
So can you please let us know how we can use LoadFromTnef() API-
1. If mailStream object contains message body only ?
2. If mailStream object contains both body and attachments ?
Thanks
Atul
Hi Atul,
Thank you for providing the additional information.
Since you are using a mix of Microsoft.Exchange and Aspose.Email's API, I'm not sure if the issue arises due to this reason. Could you please save the message as MSG by
fetching it from your exchange server using Aspose.Email's IEWSClient API and let us know your feedback? Please note that Aspose.Email works independently of Microsoft Outlook and its IEWSClient can be used for communication with Exchange server.
Abhijit Ghosh: When I am using the mailStream object in Load() API, it successfully loads the mailStream object in the MailMessage object but after that when I am calling the LoadFromTnef() API I am getting an exception.
Could you please save the mailStream as message to disc and provide us it here for our reference? It will help us investigate the issue further for your assistance.
Abhijit Ghosh: So can you please let us know how we can use LoadFromTnef() API-
1. If mailStream object contains message body only ?
2. If mailStream object contains both body and attachments ?
MailMessage contains "winmail.dat" object if the message is of TNEF nature. You may check the MailMessage object for this attachment and process it accordingly as specified in the code sample mentioned above.
Your feedback will allow us to assist you further.
Hi Atul,
Thank you for the feedback.
The version of Aspose.Email that you are using is quite old. Please download the latest version of Aspose.Email for .NET 3.7.0 and use the MailMessageLoadOptions for loading the message with TNEF contents preserved. Once the MailMessage object is available, you can further check its attachments for winmail.dat.
Sample Code
MailMessageLoadOptions options = new MailMessageLoadOptions();
options.FileCompatabilityMode = FileCompatabilityMode.PreserveTnefAttachments;
MailMessage msg = MailMessage.Load(stream, options);
foreach(Attachment att in msg.Attachments)
{
if (att.Name == "winmail.dat")
{
//Extract the TNEF contents as shown in earlier sample code
}
}
Working With IEWSClient
Aspose.Email for .NET supports working Microsoft Exchange Servers using its
ExchangeClient as well as ExchangeWebServiceClient. Please refer to our
documentation article section, Programming Exchange, for knowing about this.
Please let us know if we can be of any additional help to you in this regard.
Hi Kashif,
Thanks for providing the sample code. We will work on this and let you know the outcome.
Regarding using latest Aspose dll, just for your information we have purchased license for Aspose 1.7 version so can we upgrade to latest Aspose dll (3.7 version) by using older license ?
Thanks
Atul
Hi Atul,
The old license will not work with the latest version of Aspose.Email for .NET 3.7.0 as each license has a specific expiry date and can work with product updates released during that duration only. However, you can try it by obtaining a
30 day temporary license free of cost and let us know your feedback.
Also, please try to use Aspose API only at your end as its fetch message doesn’t require any such mode to be set for retrieving TNEF messages. Please let us know your feedback then.