We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to load embedded message

Hi all,

Happy new year

I have an eml file which has a .msg / rfc822 message as an attachment.

I am able to load the eml file and can see the attachment has IsEmbeddedMessage true. I want to load this embedded message as a new message and read the header values

Any pointers how can i load the attachment as a new MailMessage in .net?

I am not a developer by any means, just trying to put a quick and dirty proof of concept together

thanks a lot – Varun

@varunagg

I suggest you to please visit the following thread link for your kind reference.

Thanks Mudassir, i am not able to open the link it says Oops! That page is private.

Are you able to open the link ?

@varunagg

Can you please try again on your end.

Thanks Mudassir. I can read the post now.

I am using version 20.12

Here is the snippet of code in Powershell

Add-type “C:\aspose.email.20.12.0\lib\net35\Aspose.Email.dll”
$FileToLoad = “c:\test\file1.eml”

$LoadOptions = new-object Aspose.Email.EmlLoadOptions
$LoadOptions.PreserveEmbeddedMessageFormat = $true

$objMailmsg = [Aspose.Email.MailMessage]::Load($FileToLoad, $LoadOptions)
$objMailmsg.Attachments[0].Save(“c:\varun\ra\Aspose.Save1.msg”)

The message is saved but cannot be opened in outlook

@varunagg

Can you please share the source EML file along with generated MSG file that fails to open. Please share the requested information so that I may investigate issue on my end.

Hello

sorry for late response, where and how do i upload the EML file, i do not see any option please advice

@varunagg

You can upload the source and generated files in this thread by using upload button. If the files sizes are above 9 MB, you can then upload on some file server and share download link with us.

image.png (7.7 KB)

This does not allow me to upload .EML, do i rename the eml to .jpg

Do i need to convert the EML into PDF ?

@varunagg

Please zip the package and share with us.

Sample.zip (7.0 KB)

Thanks , that worked, file is attached

@varunagg

I have tried to extract the message attachment from EML file and extracted message attachment file is corrupt. A ticket with ID EMAILNET-40062 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Thanks, has there been any progress on this?

@varunagg

We have investigated the issue further on our end. The inline message is stored as EML, and when you save from an attachment, it is saved as is - in EML format. In order to save in msg format you have to load it in MailMessage and then save in msg like this:

            MailMessage objMailmsg = MailMessage.Load(path + "Sample.eml", options);
            objMailmsg.Attachments[0].Save(path + "Aspose.Save1.eml");
            MailMessage msg = MailMessage.Load(objMailmsg.Attachments[0].ContentStream);
            msg.Save(path + "Aspose.Save1.msg", SaveOptions.DefaultMsgUnicode);

thanks, is it not possible to save the attachment directly as a .msg instead of saving it as .eml first and then .msg

@varunagg

Actually. EML is different file format and MSG is different. The API does support converting EML to MSG file and that we have shared with you.

Thanks a lot, i will get back on this soon

@varunagg

Sure, we will be looking forward to hear from you.

This works well, so thanks a lot

I have one more question.

Before i save the attachment as .msg the properties of the attachment IsEmbeddedMessage is True, ContentType is message/rfc822 and TransferEncoding is Binary

When i try to add the same attachment back to the message the properties are IsEmbeddedMessage is False, ContentType is IsEmbeddedMessage is True, ContentType is message/rfc822 and TransferEncoding is Binary and TransferEncoding is Base64

Please can you advice how can i add the attachment like it was there originally