Retrieve Attachement From EML file

Hi,


We have a C# .NET WebSite which allow me to retrieve eml file from a SQL server database. I am using your Email Component to format this file and open attachement.

I can do it without problem with pdf but when it’s an excel file, if I do not define the extension of the file by XLSX, it retrieve it as ZIP file

When I define it as XLSX, I am able to open the excel file but I receive error messages from excel which is saying that the file is corrupted. But the original file is perfect.

My code is like that:

Response.ContentType = “application/octet-stream”; //Without specify the extension
Response.BinaryWrite(ToByteArray(sAtt));

regards
Guillaume
HI Guillaume,

Thank you for writing to us.

DL-SGA-A78Admins:

We have a C# .NET WebSite which allow me to retrieve eml file from a SQL server database. I am using your Email Component to format this file and open attachement.
Can you please save the EML file to the disc after retrieving from the SQL server database and see if its attachments are proper? Please provide us such an EML file after retrieving from the SQL database for our analysis. If possible, provide us with the original EML file as well (prior to storing in SQL database) so that we can analyze the original attachment.

DL-SGA-A78Admins:

I can do it without problem with pdf but when it's an excel file, if I do not define the extension of the file by XLSX, it retrieve it as ZIP file


I would suggest to test the extracted Excel attachment by saving it to the disc and see if it is saved properly or not? This will enable us to identify if the component is doing some problem with the XLSX files or it is saved properly.

DL-SGA-A78Admins:

My code is like that:

Response.ContentType = "application/octet-stream"; //Without specify the extension
Response.BinaryWrite(ToByteArray(sAtt));

Can you please try:

Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(stream.ToArray());

and see if it solves your problem. Please provide us your sample code (you can ignore the retrieving from SQL server part) in case the problem still persists. We will try to assist you further as soon as possible.


Thank you for your help.

I tested the original EML file and I can open it manually wihout any problem with the XLSX file.
I extract the EML file from SQL thru a BCP command and I can also open the XLSX file without any problem.

I tried to change the code by this Response.ContentType = "application/vnd.ms-excel";

but this mine is valid for XLS and I do not have problem with XLS

The new mime for XLSX is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

I already test it before to create this topic and it's failed.

So please find here an eml example. May be you can find the best way to open the attachement.
I didn't yet test for docx and other Office 2010 version but I hope to do not have this kind of problem.

Regards
Guillaume

Hi Guillaume,


Thank you for the feedback.

Can you please tell us which version of Aspose.Email for .NET you are using? With the latest version Aspose.Email for .NET 2.4.0, I found a bug of no attachments detected. Please confirm to us the version you are using, so that we can further investigate this issue and report it to our development team for further investigation.

it’s the version 2.2.0. I will try by upgraded it to the new version if you validate it.


Regards
Guillaume
Hi Guillaume,

DL-SGA-A78Admins:
it's the version 2.2.0. I will try by upgraded it to the new version if you validate it.

Even the Aspose.Email for .NET 2.2.0 doesn't show any attachments in your reference EML file. Anyways, I have reported the issue of attachments not detected by latest version of Aspose.Email for .NET 2.4.0 as NETWORKNET-33543 in our issue tracking system.

As the attachments can't be detected at my end, I was unable to test the issue of "Extraction of attachment XLSX file as Zip". However, I have mentioned this issue as well to our development team for consideration. I will update you here once there is any information in this regard.

PS: Is it possible for you to provide us with another EML file with XLSX attachments that can be processed using the 2.4.0, we will look into it and assist you further as soon as possible. You can use the 2.4.0 version with the following code to check if it detects the attachments properly.

MailMessage msg = MailMessage.Load("filename.eml", MessageFormat.Eml);

Console.WriteLine("Attachments Count: {0}", msg.Attachments.Count);

Hi,


I tested my application with the 2.4 version. I still able to detect all attachment but I still have same error message which is saying that my file is corrupted.

Regards
Guillaume

Hi Guillaume,

I further investigated this issue and found that your sample file fileName.EML is corrupt. If you open this file in notepad, you will see that the first 8 Bytes are wrong. I removed these manually and used the following code to extract the XLSX file, which extracted properly. In addition, I would request you to please have a look at this LINK for your reference, which shows that it’s not an issue at Aspose.Email end. Please try the following code at your end and let us know your feedback

try
{
    {
        FileStream file = new FileStream(path, FileMode.Open);
        byte[] bytes = new byte[file.Length];
        file.Read(bytes, 0, (int)file.Length);
        MemoryStream ms = new MemoryStream();
        ms.Write(bytes, 0, (int)file.Length);
        file.Close();

        //Get the XLSX attachment from the EML file
        MailMessage msg = MailMessage.Load(ms, MessageFormat.Eml);
        ms.Close();

        //Get the XLSX attachment from the EML file
        Attachment att = msg.Attachments[0];

        //Save the attachment to Stream
        MemoryStream ms2 = new MemoryStream();
        byte[] buffer;
        att.Save(ms2);
        ms2.Position = 0;
        buffer = ms2.ToArray(); //save in byte[] array

        //write to Response
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", att.Name));
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.BinaryWrite(buffer);
        Response.End();
    }
}
catch (Exception ex)
{
    if (!(ex is System.Threading.ThreadAbortException))
    {
        //Other error handling code here
    }
}

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


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

Hi,
We have already facing some issue related to download email using EAGetEmail third party .dll.

Point 1- We have retrieve email and parse but some cases excel attachment or doc attachment show .eml format.

How can resolve this problem.

Regards,
Dinesh kumar sharma

@9015746611,

Can you please share the complete details of the issue/requirement that you are facing along with source code used and test file. Please also share that which version of Aspose.Email for .NET you are using on your end.