Convert Outlook Meeting / Calendar - Start & End Date incorrect

Hello,

We are converting Outlook messages (msg) to PDF by going through the HTML format.

To format the sending date, we use :

mhtOptions.FormatTemplates[MhtTemplateName.DateTime] = String.Concat(Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern, " ", Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern);

It works well for the sending date (correct format, correct time zone) for classic emails.

However, with appointment emails, the date format for the Start and End fields is correct, but there is a one-hour time difference.

Source code :

Thread.CurrentThread.CurrentCulture = new CultureInfo(“fr-FR”);

FileStream docStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

MemoryStream ms = new MemoryStream();

MhtSaveOptions mhtOptions = Aspose.Email.SaveOptions.DefaultMhtml;

mhtOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.WriteCompleteEmailAddress | MhtFormatOptions.RenderCalendarEvent | MhtFormatOptions.RenderTaskFields | MhtFormatOptions.RenderVCardInfo;

mhtOptions.FormatTemplates[“From”] = mhtOptions.FormatTemplates[“From”].Replace(“From:”, “Da:”);

mhtOptions.FormatTemplates[MhtTemplateName.From] = mhtOptions.FormatTemplates[MhtTemplateName.From].Replace(“From”, “De”);

mhtOptions.FormatTemplates[MhtTemplateName.Cc] = mhtOptions.FormatTemplates[MhtTemplateName.Cc].Replace(“Cc”, “Cc”);

mhtOptions.FormatTemplates[MhtTemplateName.Bcc] = mhtOptions.FormatTemplates[MhtTemplateName.Bcc].Replace(“Bcc”, “Bcc”);

mhtOptions.FormatTemplates[MhtTemplateName.To] = mhtOptions.FormatTemplates[MhtTemplateName.To].Replace(“To”, “A”);

mhtOptions.FormatTemplates[MhtTemplateName.Subject] = mhtOptions.FormatTemplates[MhtTemplateName.Subject].Replace(“Subject”, “Objet”);

mhtOptions.FormatTemplates[MhtTemplateName.Sent] = mhtOptions.FormatTemplates[MhtTemplateName.Sent].Replace(“Sent”, “Envoyé le”);

mhtOptions.FormatTemplates[MhtTemplateName.DateTime] = String.Concat(currentCulture.DateTimeFormat.LongDatePattern, " ", currentCulture.DateTimeFormat.LongTimePattern);

mhtOptions.FormatTemplates[MhtTemplateName.DateTime] = String.Concat(Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern, " ", Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern);

mhtOptions.FormatTemplates[MhtTemplateName.ShowTimeAs] = mhtOptions.FormatTemplates[MhtTemplateName.ShowTimeAs].Replace(“Show Time As”, “Afficher la disponibilité”);

mhtOptions.FormatTemplates[MhtTemplateName.Location] = mhtOptions.FormatTemplates[MhtTemplateName.Location].Replace(“Location”, “Emplacement”);

mhtOptions.FormatTemplates[MhtTemplateName.Start] = mhtOptions.FormatTemplates[MhtTemplateName.Start].Replace(“Start”, “Début”);

mhtOptions.FormatTemplates[MhtTemplateName.End] = mhtOptions.FormatTemplates[MhtTemplateName.End].Replace(“End”, “Fin”);

mhtOptions.FormatTemplates[MhtTemplateName.Importance] = mhtOptions.FormatTemplates[MhtTemplateName.Importance].Replace(“Importance”, “Importance”);

mhtOptions.FormatTemplates[MhtTemplateName.Organizer] = mhtOptions.FormatTemplates[MhtTemplateName.Organizer].Replace(“Organizer”, “Organisateur”);

mhtOptions.FormatTemplates[MhtTemplateName.Recurrence] = mhtOptions.FormatTemplates[MhtTemplateName.Recurrence].Replace(“Recurrence”, “Périodicité”);

mhtOptions.FormatTemplates[MhtTemplateName.RecurrencePattern] = mhtOptions.FormatTemplates[MhtTemplateName.RecurrencePattern].Replace(“Recurrence Pattern”, “Critère de périodicité”);

mhtOptions.FormatTemplates[MhtTemplateName.RequiredAttendees] = mhtOptions.FormatTemplates[MhtTemplateName.RequiredAttendees].Replace(“Required Attendees”, “Participants obligatoires”);

var mapiMessage = MapiMessage.Load(docStream, new MsgLoadOptions());

mapiMessage.Save(ms, mhtOptions);

mapiMessage.Save(“c:\temp\message.html”, mhtOptions);

…/…

In Message.html, the Start and End times are found with a one-hour time difference.

@tparassin

It seems that you are experiencing a one-hour time difference when converting Outlook appointment emails to PDF format. This issue may be related to how the date and time are being handled during the conversion process.

To address this, you can try using the PreserveOriginalDate option in your MhtSaveOptions. Setting this option to false may help in maintaining the correct time zone for the Start and End fields. Here’s how you can implement this in your code:

MhtSaveOptions mhtOptions = Aspose.Email.SaveOptions.DefaultMhtml;
mhtOptions.PreserveOriginalDate = false; // Ensure original date is not preserved
// Other formatting options...
mapiMessage.Save(ms, mhtOptions);

By adjusting this setting, you should be able to resolve the time discrepancy you are encountering. If the issue persists, consider checking the time zone settings of the original appointment in Outlook to ensure they are correctly set.

For further details, you can refer to the MhtSaveOptions class in the Aspose documentation here.

If you have any more questions or need further assistance, feel free to ask!

Cool, that fixes the problem well.
Thank you

@mathiasmollon ,

You’re welcome. If you have further questions or need assistance, feel free to reach out.