Free Support Forum - aspose.com

Changing the time zone when converting emails to MHT

We convert emails to MHT files using the following code:

using (MailMessage msg = MailMessage.Load(emailFilePath, messageFormat))
{
using (MemoryStream mhtStream = new MemoryStream())
{
msg.Save(mhtStream, MessageFormat.Mht);

}
}

The sent date is rendered using the local system time zone. Our users would like to be able to configure the time zone that is used for the sent date (and any other dates that may be displayed in the MHT).

Is it possible to change the time zone that is used?

Thanks.

Hi Reuben,


Thank you for writing to us.

After an initial investigation, I could not find any such option to specify the original time zone when the message is converted to MHT. I would further discuss this requirement with our development team and update you here once I have updated information on this. Your patience till then is highly appreciated in this regard.

Hi Reuben,


I have logged an enhancement ticket in our issue tracking system, with id: NETWORKNET-33586, for rendering sent date in original time zone while conversion to MHT. You will be notified here once this enhancement is implemented, and appreciate your patience in this regard.

Thanks, but please note that we would like the option to render the sent date in any time zone that the user may choose - not just the original time zone.

Hi Reuben,


You are welcome.

I have logged your additional comments against the issue ID: NETWORKNET-33586 for development team’s consideration. Once we have any update in this regard, you will be notified here via this thread.

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


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

Thanks for adding the MailMessage.TimeZoneOffset property, however I have identified an issue with it. Logically, you would expect the TimeZoneOffset to be relative to UTC, but it seems to be relative to the local time zone.

For example, I sent a particular email at 2:46 PM on 28 Feb 2013 in Melbourne (AEDT UTC+11). This time equates to:

  • 2:46 PM on 28 Feb 2013 in Melbourne (AEDT UTC+11)
  • 9:16 AM on 28 Feb 2013 in India (IST UTC+5:30)
  • 3:46 AM on 28 Feb 2013 in UTC

I ran the following code to generate an MHT using the local time zone of the machine (UTC+11):

msg.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
msg.Save(@“C:\output1.mht”, MessageFormat.Mht);

The sent date displayed in the resulting MHT is “1 Mar 2013 01:46:03 +1100”, not
2:46 PM on 28 Feb 2013 as expected.

I ran the following code:

msg.TimeZoneOffset = TimeZoneInfo.FindSystemTimeZoneById(“India Standard Time”).GetUtcOffset(msg.Date);
msg.Save(@“C:\output2.mht”, MessageFormat.Mht);

The sent date displayed in the resulting MHT is “28 Feb 2013 20:16:03 +0530”, not
9:16 AM on 28 Feb 2013 as expected.

I ran the following code:

msg.TimeZoneOffset = TimeZoneInfo.FindSystemTimeZoneById(“UTC”).GetUtcOffset(msg.Date);
msg.Save(@“C:\output3.mht”, MessageFormat.Mht);

The sent date displayed in the resulting MHT is “28 Feb 2013 14:46:03 +0000”, not
3:46 AM on 28 Feb 2013 as expected.

Of course, the discrepancies are due to the fact that the TimeZoneOffset is relative to the local time zone, not UTC. I can take this into account by setting TimeZoneOffset to minus , but this will cause the UTC offset that is displayed at the end of the sent date in the MHT to be incorrect.

For example, with the following code:

msg.TimeZoneOffset = TimeZoneInfo.FindSystemTimeZoneById(“UTC”).GetUtcOffset(msg.Date) - TimeZoneInfo.Local.GetUtcOffset(msg.Date);

The sent date displayed in the resulting MHT is “28 Feb 2013 03:46:03 -1100”. This matches the expected time of 3:46 AM on 28 Feb 2013 in the UTC time zone. However the offset of -1100 does not match the expected offset of +0000.

In summary, would it be possible to make TimeZoneOffset relative to UTC rather than the local time zone of the machine?

I have attached the email I mentioned, along with output1.mht, output2.mht and output3.mht.

Thanks,

Reuben

Hi Reuben,


Thanks for sharing your analysis.

I have analyzed the information and can observe the behavior of this new property as explained by you. I have passed this information to the development team and will write back here as soon as some feedback is received from the developers.

Hi Reuben,


This is just to inform you that we have reopened the ticket NETWORKNET-33586 for further consideration of its implementation as per your requirements. Development team is currently investigating if implementation like this may affect other customers or not. In any case, the functionality may be implemented in the upcoming release of Aspose.Email for .NET 2.8.0. I’ll keep you posted here in case there is something important to share with you.

We appreciate your patience in this regard.

Hi Kashif,

Thanks for the update. The development team may like to consider adding a second property like TimeZoneOffsetUtc to prevent the change affecting other customers.

Regards,

Reuben

Hi Reuben,


Thanks for your suggestion.

This is already under consideration by the development team and we’ll update you once this functionality is modified.

Hi Reuben,


While development team is looking to fix this issue in upcoming product release, you may use the following workaround method to get the time in Universal format while printing to MHT.


MailMessage eml = MailMessage.Load(fileName);

if (eml.Date.Kind == DateTimeKind.Local)

{

eml.Date = eml.Date.ToUniversalTime();

}