Exception when trying load EML file

Hi,

I got an issue trying to load some eml files, these are the exception messages:

--System.FormatException: The specified content type is invalid.
--System.ArgumentException: '5601' is not a supported encoding name.

I am using the latest version of Aspose.Email.

I have one eml file for each exception, if you needed just let me know.

Please if there is something that you could do to fix this I'll really apreciate.

Thanks,

Hi Gerardo,


We are sorry for the inconvenience you are facing.

I would like to share with you that we got such exception in past as well due to various internal reasons that were then fixed by our development team in the follow up release. I would request you to please provide us with the EML files for the mentioned issues. We will provide these to our development team for further investigation and will try to provide solution as soon as possible.

Hi Kashif,


Code:

MailMessage message = MailMessage.Load(“example.eml”, MessageFormat.Eml);

Attached the example file.

Regards,

Thanks,

Hi Gerardo,


Thank you for providing us the source files.

I was able to reproduce the issues you mentioned using the latest version of Aspose.Email for .NET 2.2.0 at my end. I have logged these bugs in our issue tracking system for further investigation by our development team. We will update you here once we have the fix ready for the resolution of these issues, and appreciate your patience in this regard.

The bugs have been logged as NETWORKNET-33500 and NETWORKNET-33501 in our issue tracking system.

The issues you have found earlier (filed as NETWORKNET-33500;NETWORKNET-33501) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi,


I am experience similar issues, running Aspose.Email for .NET v3.3.0, specifically “The specified content type is invalid”.

If I edit the eml file and change the content type from png to image/png and pdf to application/pdf respectively, the message loads fine.

I understand these may not be valid content types, however I would expect to be able to load the message as other mail clients do not have an issue with this example.

I have attached a sample eml file.

Regards
Trent

Hi Trent,


Aspose.Email provides facility to skip the validity checks during Load operation. Following sample code loads this message and saves the attachment PDF and inline image on disc.

MailMessage mail = MailMessage.Load(@“D:\Aspose\Invalid Content Type.eml”, FileCompatibilityMode.SkipValidityChecking);
foreach (Attachment att in mail.Attachments)
{
if(att.ContentType.MediaType == “pdf/”)
att.Save(att.Name + “pdf”);
}
foreach (LinkedResource res in mail.LinkedResources)
{
if (res.ContentType.MediaType == “png/”)
res.Save(“Image.png”);
}

Could you please give it a try and let us know the feedback?

Thanks Kashif,


I will try this tomorrow. I will also need to use FileCompatibilityMode on saving which leads me to another question.

I am current saving a MailMessage to a MemoryStream in eml format using the following:

message.Save(stream, MessageFormat.Eml);

Can you please tell me how I can specify FileCompatibilityMode with MessageFormat and/or MailMessageSaveOptions when saving?

Thanks
Trent

Hi Trent,


I have tried different messages including the one having content type issues. However it is found that once the message is loaded (with or without FileCompatibilityMode), it can be saved to stream or disc without any error. Please feel free to write us back if you have any other query in this regard.

Hi Kashif,


Except where this email is an embedded attachment within another MailMessage and I need to save this MailMessage in Outlook MSG format. If I don’t specify MessageFormat.Msg, the output defaults to eml which is not what I want. If I specify MessageFormat.Msg, I get an exception.

Regards
Trent

Hi Trent,

Thank you for writing to us.

If you are loading a message (with another attachment message) and saving the attachment directly, it will always be saved as EML. This is the default behavior. However, you can use the following code sample to save the attachment MSG as Outlook MSG file.I have also attached a sample MSG here for your reference. Please give a try to the code sample and let us know your feedback.

Sample Code:

string dir = “EMAIL_496660\”;

MailMessage mailMsg = MailMessage.Load(dir + "message 1.msg");

Attachment att = mailMsg.Attachments[0];

MemoryStream ms = new MemoryStream();

att.Save(ms);

MailMessage mailMsg2 = MailMessage.Load(ms);

mailMsg2.Save(dir + "TestMsg.msg", MailMessageSaveType.OutlookMessageFormat);