Free Support Forum - aspose.com

Problems saving MSG to EML

Hi,


In my project, I am using ImapClient to download email and save to disk in Outlook msg format. At a later time, I processing these saved msg files by loading back into a MailMessage object. I have no problems processing the msg files and extracting the attachments and contents.

However, for emails that I cannot process for whatever reason (lets say a password protected attachment that I cannot open) i forward this email back to the recipient as an attachment to a new MailMessage and send via SmtpClient.

The code I am using to do this is as follows (as per a previous thread post):

MailMessage message = new MailMessage(“from”, “to”, “subject”, “body”);

// Load the error email
using (var error = MailMessage.Load(“PathToMsgFile”))
{
// Save as eml
MemoryStream ms = new MemoryStream();
error.Save(ms, MessageFormat.Eml);

var attachment = new Attachment(ms, “Test”, “message/rfc822”);
message.AddAttachment(att);
}

smtp.Send(message);

From what I can tell of all of the debugging I have been doing is that the conversion from MSG to EML does not appear to be producing a compliant EML file. I have tested saving EML to a file and often these files won’t show any attachments if there are any whilst they are present in the MSG file. The resultant EML files also take a long time to open in outlook.

I have also tested this on my production server running Windows Server 2008 R2 and have found that the call to SmtpClient.Send hangs if the content type is set to message/rfc822, if I remove this and just attached a .eml file this is no problem (however the attachment has the same symptoms as described above).

Regards
Trent

Hi Trent,

Thanks for contacting Aspose.Email support team.

I have analyzed the whole information and following are the findings:

tcromer:
In my project, I am using ImapClient to download email and save to disk in Outlook msg format. At a later time, I processing these saved msg files by loading back into a MailMessage object. I have no problems processing the msg files and extracting the attachments and contents.

I followed all these steps and no error was found as you have already informed.

tcromer:
However, for emails that I cannot process for whatever reason (lets say a password protected attachment that I cannot open) i forward this email back to the recipient as an attachment to a new MailMessage and send via SmtpClient.

The code I am using to do this is as follows (as per a previous thread post):
///////
//Sample code here
///////

I used my test accounts to fetch mail from the INBOX. This email was having attachments. I created a new message and then attached the fetched message in accordance with the sample code. This email was sent and was received on other other with all attachments intact.

tcromer:
From what I can tell of all of the debugging I have been doing is that the conversion from MSG to EML does not appear to be producing a compliant EML file. I have tested saving EML to a file and often these files won't show any attachments if there are any whilst they are present in the MSG file. The resultant EML files also take a long time to open in outlook.
I saved the fetched message as EML and found that this email was saved properly along with the attachments. It took normal time to load the saved EML into Outlook 2010 installed on my system.

tcromer:
I have also tested this on my production server running Windows Server 2008 R2 and have found that the call to SmtpClient.Send hangs if the content type is set to message/rfc822, if I remove this and just attached a .eml file this is no problem (however the attachment has the same symptoms as described above).
I created new message, attached the earlier fetched message with content type "message/rfc822" and called the SmtpClient.Send function. No hang was observed during the mail sending process and it was sent successfully.

I am afraid to inform that I could not re-produce the issue here. Could you please send us some sample MSG file(s) so that we may perform few tests to re-produce the issue here. It will help us to identify the problem and assist you as soon as possible.

Hi Kashif,


Please find attached a sample MailMessage fetched from ImapClient and saved in MSG format and EML format. The email contains an inline image and an attached word document. The MSG is displayed fine through Outlook whilst the EML is not.

Regards
Trent

Hi Trent,


We are sorry for any inconvenience caused to you.

I am afraid to inform that still I am unable to reproduce the issue here. I used your sample MSG file and converted it to EML using Aspose.Email. I opened both the files in Outlook and could not observe any difference. Please have a look at the attached screen shot “MSG_EML_Comparison.png”.

Second test was performed to attach your MSG with a new message and sent to my test account. On the receiving end all the inline images and doc attachment were visible properly and no issue was observed. A screen shot at the receiving end is attached as “Original Message attached with mail.png” for your kind reference.

Could you please send me the snapshot of differences in both the MSG and EML files in Outlook as well as in the mail client on receiving end. It will help us to understand the issue and provide assistance.

Could you please confirm if you are using the latest version of Aspose.Email for .NET 2.6.0 in your application.

Thanks for your patience and understanding in this regard.