Free Support Forum - aspose.com

Saving mail as .MSG format

Hi,

I was just evaluating Aspose.Email product. I have seen that there is method in Aspose.Email.Mail.MailMessage class named as Load(). Now Load() method can be called by 6 ways which is actually a combination of “Calling through Stream Object” and “Calling through some file name”.

I am pretty much interested in calling Load() method through “Stream object”.

What kind of stream it accepts ?

Actually I am working at Transport layer of Microsoft Exchange environment. So when ever any user sends a mail through Outlook it goes through Exchange Server and first hit at Transport Layer. Now at Transport Layer I got the mail in the form of “Microsoft.Exchange.Data.Transport.MailItem”. Through this MailItem class and by using mailItem.GetMimeReadStream(), I can get Mime stream of the mail that user has send.

So my question here is can I pass the stream got from mailItem.GetMimeReadStream() to the MailMessage.Load() function ?

Regards,
Atul

Hi Atul,

Aspose.Email for .NET’s MailMessage class can load email messages in 3 formats EML, MSG and MHT. Whether you load from a stream or file, the Load() method will work only if the data format is EML, MSG or MHT. It will not work with Microsoft’s MailItem class.

You may also download the messages from Exchange Server with Aspose.Email, please refer to http://www.aspose.com/documentation/.net-components/aspose.email-for-.net/download-messages-from-exchange-server-folders-and-subfolders-recursively.html article for documentation and code sample.

Hi Saqib,

Any specific reason why it wont work with Microsoft MailItem class ?

If Load() is accepting a Stream object as a input parameter and if we can get Stream object through MailItem class as mentioned above than MailItem.Load() should also work for the same. Through Microsoft’s MailItem class we eventually get stream of mail send by user through Outlook.

Even I have tested your product with this and I am getting the same result as supplying the stream of an .eml/.MSG file.

Regards,
Atul

Hi Atul,

The Stream is a storage location and any thing could be stored in stream e.g. an email, zip, pdf word doc, string etc. Our MailMessage's Load() method will only work if the stream contains data that is in supported formats.

Hello Saqib,

The Stream got from MailItem.GetMimeReadStream() is a stream of mail that has been send by the user through Outlook. Because I debug the transport agent and verify the same so its confirm that stream contains email message.

So if the statement that I stated above is true than can I pass stream to Load() method ?

Hi Atul,

Please save this stream to file and give either EML or MSG extension. If you can open this file with MS Outlook, then yes, theoratically you can pass it to Load() method.

Hello Saqib,

Yes, I can save that stream to .eml file and can view that .eml file with outlook.

Regards,
Atul

Then it should also load with Load(stream, MessageFormat.Eml). Did you try it?

Yes, I have tried it and it is giving me same result as it show when we Load an eml file using Load() method.