Inconsistent MailMessage.TimeZoneOffset between sent and unset email
Hi Nickolai,
Thank you for writing to Aspose Support team.
you want to print the UTC time in the Mhtml, you may subtract the mail
timezone offset from the date as shown in the following sample code:
MailMessage mail = MailMessage.Load(path + “Mail.msg”);
Console.WriteLine(mail.Date.ToString() + ", Kind = " + mail.Date.Kind);
Console.WriteLine("TimeZone offset = " + mail.TimeZoneOffset);
Console.WriteLine("Actual UTC Time is " + mail.Date.ToUniversalTime().ToString());
Console.WriteLine((mail.Date.ToUniversalTime() + mail.TimeZoneOffset).ToString());
mail.Date = mail.Date - mail.TimeZoneOffset ;
MemoryStream msMHTML = new MemoryStream();
MhtMessageFormatter mhtlFormat = new MhtMessageFormatter();
mhtlFormat.DateTimeFormat = “MM/dd/yy H:mm:ss tt”;
mhtlFormat.Format(mail);
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
mhtSaveOptions.MhtFormatOptions = MhtFormatOptions.None;
mail.Save(path + “Mail.mht”, mhtSaveOptions);
mail date is to be printed according to the local system timezone, you
may subtract the mail timezone offset from mail date and add your local
system timezone as shown in the following sample code.
MailMessage mail = MailMessage.Load(path + “Mail.msg”);
Console.WriteLine(mail.Date.ToString() + ", Kind = " + mail.Date.Kind);
Console.WriteLine("TimeZone offset = " + mail.TimeZoneOffset);
Console.WriteLine("Actual UTC Time is " + mail.Date.ToUniversalTime().ToString());
Console.WriteLine((mail.Date.ToUniversalTime() + mail.TimeZoneOffset).ToString());
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
mail.Date = mail.Date - mail.TimeZoneOffset + ts;
MemoryStream msMHTML = new MemoryStream();
MhtMessageFormatter mhtlFormat = new MhtMessageFormatter();
mhtlFormat.DateTimeFormat = “MM/dd/yy H:mm:ss tt”;
mhtlFormat.Format(mail);
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
mhtSaveOptions.MhtFormatOptions = MhtFormatOptions.None;
mail.Save(path + “Mail.mht”, mhtSaveOptions);
Can you explain why the timezoneoffset is different depending on where the mail is taken from?
Hi Nickolai,
I have been using Outlook 2013 and Aspose.Email 6.2.0
Hi Nickolai,
Please try it with the latest version of the API i.e Aspose.Email for .NET 6.5.0 and let us know your feedback.
I have now tried with 6.5 using Outlook 2013
Hi Nickolai,
This issue is present on multiple machines.
Hi Nickolai,
We tested the issue on Windows 7 and didn’t find any problem with your sample files with our local regional settings. Could you please guide us towards setting Danish as regional settings? Meanwhile, we are establishing a test environment of Windows Server 2012 R2 for further investigation of this issue and your guidance will help us analyze the problem in more details. We appreciate your cooperation in this regard.
Maybe it’s the same problem as in https://forum.aspose.com/t/18698&Subj=inconsistent-timestamp-between-sent-and-unsent-email#