Mapi Task behavior

Hi Aspose Team,


When i create a MapiTask by selecting start and due date as 4/28/2015 using below sample code,

MapiTask task = new MapiTask(Task.Subject, body, Task.StartDate, Task.DueDate);
task.PercentComplete = claimTask.PercentComplete;
task.EstimatedEffort = 2000;
task.ActualEffort = 20;
MemoryStream ms = new MemoryStream();
task.Save(ms, TaskSaveFormat.Msg);
ms.Position = 0;
MapiMessage msg = MapiMessage.FromStream(ms);
// Convert to TNEF eml. Such a feature would allow to send messages by mail clients,
/ where the information, specific for Outlook task, would be stored.
MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(msg.MessageClass);
MailMessage eml = mi.InterpretAsTnef(msg);
eml.From = “from address”;
eml.To.Clear();
eml.To.Add(new Aspose.Email.Mail.MailAddress(“Toaddress”);
IEWSClient client = EWSClient.GetEWSClient("----", “—”, “—”, “–”);
client.Send(eml);

After sent it to the assigned user when I open the task email in outlook it is showing 4/27/2015 as incorrect start and due date.
Please any help to investigate this would be really helpful for me.
Do i need to time zone? I don’t believe so because I tried with Microsoft outlook, there is no option to set the time zone when create a new Task and MS Outlook works as expected.

Thanks in advance
Vipin Panwar

Hi Vipin,

Thank you for your inquiry.

I was able to observe the issue as the API is not taking local timezone offset into consideration while setting the start and due date. However, you can achieve this by setting the timezone offset in these fields as shown in the following code sample.

Code:

TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
int iHours = ts.Hours;
MapiTask task = new MapiTask("MapiTask Time May 1st, 2015 - 05.00 AM", "Testing Task timing issues", new DateTime(2015, 5, 1, iHours, 0, 0), new DateTime(2015, 5, 1, iHours, 0, 0));
//must be
task.State = MapiTaskState.NotAssigned;
MemoryStream ms = new MemoryStream();
task.Save(ms, TaskSaveFormat.Msg);
ms.Position = 0;
MapiMessage msg = MapiMessage.FromStream(ms);

// Convert to TNEF eml. Such a feature would allow to send messages by mail clients,
// where the information, specific for Outlook task, would be stored.
MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(msg.MessageClass);
MailMessage eml = mi.InterpretAsTnef(msg);
eml.From = "from@domain.com";
eml.To.Clear();
eml.To.Add(new Aspose.Email.Mail.MailAddress("to@domain.com"));

IEWSClient client = GetAsposeEWSClient();
client.Send(eml);

Hi Muhammad,


Thanks to observe this oddy or freak behavior of API.
I tried with your sample code but the issue still exist it’s behavior is same.
Please see the attached email task start and end date 1 day prior to the date you set.

Please assist me on same asap.

Thanks in advance
Vipin Panwar

Hi Vipin,


We have again tested this issue by sending the Task using the above code sample and at the receiving end, the dates are shown correct. I am located in UTC+5 Timezone, resulting in UTC offset in Hours equal to 5. If the task is created with this offset being part of Start/Due dates and saved to disc for analysis in MFCMapi software, it shows these dates as shown in the attached screenshot which are correct. Could you please share the timezone offset information of your environment with us? Also, please save the created MSG file to disc and share that with us for our analysis.

Hi Muhammad,


I am located in (UTC+05:30) India Time Zone and i have added the time Span to the selected Start and Due date using below.

// Get the local time zone and the current local time and year.
TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);

Task.StartDate.Add(ts) ;
Task.DueDate.Add(ts) ;

Please find the attached .MSG file as you requested.
Please assist me how to implement to resolve this freak behavior of API.
Extract and double click the >MSG file. it will open in the Outlook. You can see that the date is 29 April that should be 30th April that i selected from UI.

Let me know if additional information is required.

Thanks in advance
Vipin Panwar

Hi Vipin,

It seems this is not a freaky behavior of the API but wrong code usage in your example. StartDate.Add(ts) returns updated date time as DateTime object that actually has to be used. Please check the following code sample that works fine and let us know your feedback.

Code:

TimeZone localZone = TimeZone.CurrentTimeZone;
TimeSpan ts = localZone.GetUtcOffset(DateTime.Now);
DateTime dtStart = new DateTime(2015, 5, 1);
DateTime dtDue = new DateTime(2015, 5, 1);
DateTime dtStartWithTzOffset = dtStart.Add(ts);
DateTime dtDueWithTzOffset = dtDue.Add(ts);

MapiTask task = new MapiTask("MapiTask Time May 1st, 2015 - 05.00 AM", "Testing Task timing issues", dtStartWithTzOffset, dtDueWithTzOffset);
task.State = MapiTaskState.NotAssigned;
task.Save("625192\\A.msg", TaskSaveFormat.Msg);