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

Free Support Forum - aspose.com

Date of MSG attachment changes after saving file using Aspose.Email (C# .NET)

Hi, when extracting a msg attachment from a msg file or eml file the date of the message changes to the current date/time.

In when extracting the msg from the attached files the date/time of the file when opened in Outlook is the currect date, while when I open the file in Outlook and open (or extract) the attachment mail the date is not changed.

Email.zip (1.8 MB)

@andreas4e47b,

Can you please share complete sample code so that we may further investigate to help you out.

This is the code we use:

        Aspose.Email.License license = new Aspose.Email.License();
        license.SetLicense(@"Q:\Install\Ontwikkeling\Componenten\Aspose Total for .NET\Aspose.Total.lic");

        MailMessage theMessage = MailMessage.Load(@"D:\Temp\Aspose\Geen Onderwerp-135232524.eml");

        foreach (Attachment attachment in theMessage.Attachments)
        {
            string filename = string.Join("_", attachment.Name.Split(Path.GetInvalidFileNameChars()));

            if (attachment.ContentType.MediaType.Equals("message/rfc822", StringComparison.OrdinalIgnoreCase))
            {
                if (!Path.GetExtension(filename).Equals(".msg", StringComparison.OrdinalIgnoreCase))
                {
                    filename += ".msg";
                }
            }

            filename = Path.Combine(@"D:\Temp\Aspose\Output", filename);

            if (attachment.ContentType.MediaType.Equals("message/rfc822", StringComparison.OrdinalIgnoreCase))
            {
                MemoryStream ms = new MemoryStream();
                attachment.Save(ms);
                MailMessage attMsg = MailMessage.Load(ms);

                SaveOptions options = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode);
                attMsg.Save(filename, options);
            }
            else
            {
                attachment.Save(filename);
            }
        }

@andreas4e47b,

I have worked with provided sample code and have been able to observe the issue. An issue with ID EMAILNET-39513 has been created in our issue tracking system to 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.

Could you please let us know when the fix is planned.

@Chabie

This issue will be resolved in Aspose.Email 19.7 which will be released in month or two. I request for your patience until that.

I tested this today with 19.8 and it is stil not resolved.

@andreas4e47b,

We hae investigated the issue. This is not a bug but a feature of Aspose.Email. In order to avoid changing the date, please use the PreserveOriginalDates flag from MsgSaveOptions like this:


                    MailMessage attMsg = MailMessage.Load(ms);
                    MsgSaveOptions options = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode);
                    options.PreserveOriginalDates = true;
                    attMsg.Save(fileName, options);

Thank you, that solved the problem.

@andreas4e47b,

It’s good to hear things are resolved on your end. Please share with us if there is any issue incurring.