Free Support Forum - aspose.com

Incomplete mht file when saving a task


#1

Hi, when i save the attached outlook task to mht, the mht preview is not complete.
Attached are :
•task.msg : original event
•task.mht : incomplete mht generated by aspose
•task.rtf : rtf saved from outlook

task.zip (16.7 KB)

here is the code :
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

using Aspose.Words;
using Aspose.Words.Saving;
using Aspose.Email;

namespace MsgToPdf
{
class Program
{
static void Main(string[] args)
{
Aspose.Email.License licm = new Aspose.Email.License();
licm.SetLicense(“d:\temp\Aspose.Total.lic”);
Aspose.Words.License licw = new Aspose.Words.License();
licw.SetLicense(“d:\temp\Aspose.Total.lic”);
try
{
MailMessage message = MailMessage.Load(“d:\temp\samples_msg\task.msg”);
// If mail date is to be printed according to the local system timezone,
// subtract the mail timezone offset from mail date and your local system timezone
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
message.Date = message.Date - message.TimeZoneOffset + ts;

// MhtSaveOptions mhtOptions = new Aspose.Email.MhtSaveOptions();
// mhtOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.WriteCompleteEmailAddress;
MhtSaveOptions mhtOptions = Aspose.Email.SaveOptions.DefaultMhtml; //new Aspose.Email.MhtSaveOptions();
mhtOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.WriteCompleteEmailAddress | MhtFormatOptions.RenderCalendarEvent | MhtFormatOptions.RenderTaskFields | MhtFormatOptions.RenderVCardInfo;
mhtOptions.SkipInlineImages = true;

            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] = "ddd dd MMM yyyy HH:mm:ss";
            mhtOptions.FormatTemplates[MhtTemplateName.Attachments] = mhtOptions.FormatTemplates[MhtTemplateName.Attachments].Replace("Attachments", "Pièces jointes");
            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");


            message.Save("d:\\temp\\samples_msg\\task.mht", mhtOptions);
            GC.Collect();
        }
        catch (System.Exception ex)
        {
            String errmsg = ex.Message + " | " + ex.StackTrace;
            GC.Collect();
        }

    }
}

}


#2

@tparassin,

We were able to reproduce the issue that you reported. A ticket has been logged in our issue tracking system as EMAILNET-39166 to investigate it further. We will update you here as soon as additional information is available.


#3

@tparassin,

Our MailMessage corresponds to EML format, while MapiMessage corresponds to MSG format.
There is some data loss in converting these formats.
To avoid data loss, you may use MapiMessage to save MSG file in MHT format. Please test the code snippet given below and share your feedback with us. We are looking forward to your response.

MapiMessage message = MapiMessage.Load(msgPath, new MsgLoadOptions());
MhtSaveOptions mhtOptions = Aspose.Email.SaveOptions.DefaultMhtml;
mhtOptions.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.WriteCompleteEmailAddress | MhtFormatOptions.RenderCalendarEvent | MhtFormatOptions.RenderTaskFields | MhtFormatOptions.RenderVCardInfo;
mhtOptions.SkipInlineImages = true;
message.Save(msgPath + @"task.mht", mhtOptions)

#4

ok, it works …
but now, as i use MapiMessage, i can no longer adjust the time as I did with MailMessage :
// If mail date is to be printed according to the local system timezone,
// subtract the mail timezone offset from mail date and add your local system timezone
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
message.Date = message.Date - message.TimeZoneOffset + ts;
how can i do the same correction on the MapiMessage ?
thanks in advance.


#5

@tparassin,

Thank you for your feedback.

We are working on your query and will get back to you soon.


#6

@tparassin,

We used the code that we shared in our previous message with the MSG file shared by you. The generated output is attached below for your convenience. Please let us know whether you want to update the Start and Due date in the output? If not, then please share your generated output and the change that you require.

TaskMHT.jpg (29.0 KB)


#7

I need to print the mail dates according to the local system timezone.

when i was using MailMessage, i could do :
message.Date = message.Date - message.TimeZoneOffset + ts;

now that i use MapiMessage, the TimeZoneOffset property does no longer exist.
How can i do to adjust the mail dates to the local system timezone ?


#8

@tparassin,

Thank you for your query.

Please let us know whether you want to show TimeZone offset with Start Date and Due Date in task detail as it will be a new feature request which will be logged after your confirmation.

In case you want to get the date of MapiMessage in Local TimeZone, you may use the code snippet given below.

Console.WriteLine(mapiMessage.DeliveryTime.ToLocalTime());

In case our understanding of your requirement is not correct, please share a bit more detail so that we can assist you further.


#9

My need is to save the MapiMessage into Html format with the dates in local timezone.

with the code below it works for MailMessage (eml) but not for MapiMessage (msg) where the dates stay in GMT in the Html output.

MemoryStream ms = new MemoryStream();
MhtSaveOptions mhtOptions = Aspose.Email.SaveOptions.DefaultMhtml;

TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);

string ext = Path.GetExtension(inputFile).ToLower();

if (ext == “.eml”) {
message = MailMessage.Load(docStream);
message.Date = message.Date - message.TimeZoneOffset + ts;
message.Save(“d:\temp\eml.html”, mhtOptions);
} else {
mapiMessage = MapiMessage.Load(docStream, new MsgLoadOptions());
/mapiMessage.Save(“d:\temp\msg.html”, mhtOptions);
}


#10

@tparassin,

Thank you for sharing the detailed requirements.

We converted the date using the code snippet that you shared. The date converted using MailMessage showed the old timezone designator due to which it turned as incorrect.

We have logged an investigation ticket as EMAILNET-39242 in our issue tracking system to investigate the feasibility of showing date in the local timezone while converting to MHTML using both MailMessage and MapiMessage. We will update you here as soon as additional information is available regarding this.


#11

while waiting for the result of your investigation, i could use the mapiMessage.DeliveryTime.ToLocalTime() to convert the date, but :

  • when I do :
    message = MailMessage.Load(docStream);
    message.Date = message.Date - message.TimeZoneOffset + ts;
    message.Save(“d:\temp\eml.html”, mhtOptions);
    ==> the sent date value is well modified in the mhtml file with the result of "

  • but when I do :
    mapiMessage = MapiMessage.Load(docStream, new MsgLoadOptions());
    mapiMessage.ClientSubmitTime = mapiMessage.ClientSubmitTime.ToLocalTime();
    mapiMessage.Save(ms, mhtOptions);
    ==> the sent date is not modified in the mhtml file …
    Is the mapiMessage.ClientSubmitTime property readOnly ?
    Or does the sent date in the mhtml file come from another property ?


#12

@tparassin,

Thank you for your query.

No, the MapiMessage.ClientSubmitTime property is not read-only.

We investigated this scenario in detail and found that when we update the date using MailMessage.Date, the date is updated in the header which can be verified using the code snippet given below.

Console.WriteLine(mailMessage.Headers["Date"]);
mailMessage.Date = mailMessage.Date - mailMessage.TimeZoneOffset + ts;
Console.WriteLine(mailMessage.Headers["Date"]);

We tried updating the date in the header with MapiMessage using the code snippet given below. The updated date was shown in the output but when the MHTML file was generated, the date was reverted back to the original date.

Console.WriteLine(mapiMessage.Headers["Date"]);
mapiMessage.Headers["Date"] = mapiMessage.DeliveryTime.ToLocalTime().ToString("r");
Console.WriteLine(mapiMessage.Headers["Date"]);

Because the updated date was not preserved in the generated MHTML file, we have logged a ticket in our issue tracking system as EMAILNET-39245 to investigate this scenario further. We will update you here as soon as additional information is available.


#13

how can I switch this ticket to the paid support, because it’s urgent for us to get a fix ?


#14

@tparassin,

If you have purchased the paid support, log in to the paid support helpdesk with the email address used to buy the subscription. Create a new ticket with reference to this ticket to get it escalated to paid support.