DateTimes are wrong

I am using the current version for .net.

I extract all email message form a pst and save to disk files for further processing. I have discovered that the following properties are saved wrong.
Mapi.MapiPropertyTag.PR_CREATION_TIME
Mapi.MapiPropertyTag.PR_EXPIRY_TIME
Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME
Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME
message.DeliveryTime

I checked these when I extracted an email from a 2010 pst and these had valid and correct dates. I then open the saved msg message from disk and these and these properties had the date time I saved the message to disk

Is there a better way to save the message to disk where it maintains the correct datetime

@elumicor,

Could you please share you sample PST file with us? Please also try it with the latest version of the API and share your feedback with us.

The following is a snippet of my code.
Dim messageInfoCollection As MessageInfoCollection = Nothing
Try
messageInfoCollection = folderInfo.GetContents()
Catch ex As Exception
MsgBox(“Error calling folderInfo.GetContents” & vbNewLine & ", Error : " & ex.Message)
End Try
Dim msgfilename As String = “”
Dim CollCount As Integer = messageInfoCollection.Count
Dim _savetype As MailMessageSaveType
If _PstIsUnicode Then
_savetype = MailMessageSaveType.OutlookMessageFormatUnicode
Else
_savetype = MailMessageSaveType.OutlookMessageFormat
End If
Dim opt As SaveOptions = SaveOptions.CreateSaveOptions(_savetype)
For i As Integer = 0 To messageInfoCollection.Count - 1
Dim message As Mapi.MapiMessage = Nothing
Try
Dim messageInfo As MessageInfo = messageInfoCollection(i)
message = _pst.ExtractMessage(messageInfo)
#If DEBUG Then
If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME) IsNot Nothing Then
Debug.Print(CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME)).ToUniversalTime)
End If
If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME) IsNot Nothing Then
Debug.Print(CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME)).ToUniversalTime)
Debug.Print(CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME)).ToUniversalTime)
End If
If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME) IsNot Nothing Then
Debug.Print(CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME)).ToUniversalTime)
End If
If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME) IsNot Nothing Then
Debug.Print(CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME)).ToUniversalTime)
End If
If IsDate(message.DeliveryTime) AndAlso (Year(message.DeliveryTime) > 1900 And Year(message.DeliveryTime) < 3000) Then
Debug.Print(CDate(message.DeliveryTime).ToUniversalTime)
End If
If message.GetPropertyString(Mapi.MapiPropertyTag.PR_INTERNET_REFERENCES_W) IsNot Nothing Then
Debug.Print(message.Properties(Mapi.MapiPropertyTag.PR_INTERNET_REFERENCES_W).GetString)
End If
If message.GetPropertyString(Mapi.MapiPropertyTag.PR_INTERNET_REFERENCES_A) IsNot Nothing Then
Debug.Print(message.Properties(Mapi.MapiPropertyTag.PR_INTERNET_REFERENCES_A).GetString)
End If

#End If
msgfilename = String.Format("{0:000000} of {1:000000}.msg", (i + 1), CollCount)
’ save this message to disk in msg format
Try
_outputfilename = Path.Combine(SaveFileFolder, msgfilename)
message.Save(_outputfilename, SaveOptions.CreateSaveOptions(_savetype))
_ExtractedMsgCount += 1
Catch ex As Exception
#If DEBUG Then
MsgBox(String.Format(“Error Saving Message # {0}{1} Error : {2}”, i, vbNewLine, ex.Message))
#Else
_Logger.Log(String.Format(“Error Saving Message # {0}{1} Error : {2}”, i, vbNewLine, ex.Message))
#End If
End Try
Catch ex As Exception
#If DEBUG Then
MsgBox(String.Format(“Error Extracting Message # {0}{1} Error : {2}”, i, vbNewLine, ex.Message))
#Else
_Logger.Log(String.Format(“Error Extracting Message # {0}{1} Error : {2}”, i, vbNewLine, ex.Message))
#End If
End Try
Next

The version of Aspose.Email is 18.5
zl_bailey-s_000.zip (8.1 MB)

@elumicor,

Could you please share the specific folder from which to check the messages? There are multiple folders with many messages in these and it is difficult to identify the specific case from these.

“Sent Items” first message

@elumicor,

We checked the first message from Sent Items and dates retrieved by API are same as shown in Outlook Spy or MFCMapi. Either we are not referring to the same message or you are using some older version of the API. Please try it with latest version of the API and let us know your feedback. If the issue still persists, we would request you to extract such a message file, add it to a new PST, test the new PST (having) that single message and share it with us if the issue still persists. Any screenshots or observed output data shared with us will help us to investigate the issue further.

The info below was produced using Aspose.Email for .NET version 18.5 in my test program
1. I initialized the Aspose.Email license with no problem
2. I saved the info for first message and the message in the “Sent Items” folder to disk file with the following code.
Dim mm As MailMessage = Nothing
Dim message As Mapi.MapiMessage = Nothing
Dim Conv_opt As MailConversionOptions = Nothing
Conv_opt = New MailConversionOptions()
Conv_opt.PreserveEmbeddedMessageFormat = True

		Dim _savetype As MailMessageSaveType = MailMessageSaveType.OutlookMessageFormatUnicode
		Dim Saveopt As SaveOptions = SaveOptions.CreateSaveOptions(_savetype)

		message = _PST.ExtractMessage(MsgInfo).ToMapiMessageItem
		mm = message.ToMailMessage(Conv_opt) '_PST.ExtractMessage(MsgInfo).ToMailMessage
		Debug.Print(String.Format("{0}Subject : {1}", vbNewLine, message.Subject))
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_CREATION_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_EXPIRY_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_LAST_MODIFICATION_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_CLIENT_SUBMIT_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME)).ToUniversalTime))
		End If
		If IsDate(message.DeliveryTime) AndAlso (Year(message.DeliveryTime) > 1900 And Year(message.DeliveryTime) < 3000) Then
			Debug.Print(String.Format("DeliveryTime : {0:u}", CDate(message.DeliveryTime).ToUniversalTime))
		End If
		' save this message to disk in msg format
		Try
			If Directory.Exists(_outDir) = False Then Directory.CreateDirectory(_outDir)

			Dim _outputfilename As String = Path.Combine(_outDir, String.Format(msgfilename, cnt))
			message.Save(_outputfilename, SaveOptions.CreateSaveOptions(_savetype))
		Catch ex As Exception

#If DEBUG Then
MsgBox(String.Format(“Error Saving Message # {0}{1} Error : {2}”, cnt, vbNewLine, ex.Message))
#End If
End Try

3. I opened the saved msg file with code in a procedure called LoadMsgGoodWay with the following results.
	Here's the code:
Public Sub LoadMsgGoodWay(ByVal filename As String)
	Dim mm As MailMessage = Nothing
	Dim message As Mapi.MapiMessage = Nothing
	Dim Conv_opt As MailConversionOptions = Nothing
	Conv_opt = New MailConversionOptions()
	Conv_opt.PreserveEmbeddedMessageFormat = True
	Try
		Debug.Print("Loading eMail Using Goodway")
		' Detect file format and Gets the detected load format
		Dim info As FileFormatInfo = Tools.FileFormatUtil.DetectFileFormat(filename)
		Debug.Print(String.Format("The message format is: {0}", info.FileFormatType.ToString))
		Dim _loadoptions As LoadOptions = Nothing

		Select Case info.FileFormatType
			Case Aspose.Email.FileFormatType.Eml
				_loadoptions = New EmlLoadOptions
			Case Aspose.Email.FileFormatType.Emlx
				_loadoptions = New EmlxLoadOptions
			Case Aspose.Email.FileFormatType.Msg
				_loadoptions = New MsgLoadOptions
			Case Aspose.Email.FileFormatType.Tnef
				_loadoptions = New TnefLoadOptions
		End Select
		message = Mapi.MapiMessage.FromFile(filename)
		mm = message.ToMailMessage(Conv_opt)
		Debug.Print(String.Format("{0}Subject : {1}", vbNewLine, message.Subject))
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_CREATION_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_EXPIRY_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_LAST_MODIFICATION_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_CLIENT_SUBMIT_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME)).ToUniversalTime))
		End If
		If IsDate(message.DeliveryTime) AndAlso (Year(message.DeliveryTime) > 1900 And Year(message.DeliveryTime) < 3000) Then
			Debug.Print(String.Format("DeliveryTime : {0:u}", CDate(message.DeliveryTime).ToUniversalTime))
		End If
	Catch ex As Exception

#If DEBUG Then
Stop
#End If
End Try

End Sub

Debug output:
Loading eMail Using Goodway
The message format is: Msg

Subject : Cavell Energy Corporation
PR_CREATION_TIME : 2010-06-18 22:41:09Z
PR_LAST_MODIFICATION_TIME : 2010-06-18 22:41:09Z
PR_CLIENT_SUBMIT_TIME : 2001-10-30 20:01:00Z
DeliveryTime : 2001-10-30 20:01:00Z

4. I opened the saved msg file with code in a procedure called LoadMsgBadWay with the following results.
	Here's the code:
Public Sub LoadMsgBadWay(ByVal filename As String)
	Dim mm As MailMessage = Nothing
	Dim message As Mapi.MapiMessage = Nothing
	Try
		Debug.Print("Loading eMail Using Badway")
		' Detect file format and Gets the detected load format
		Dim info As FileFormatInfo = Tools.FileFormatUtil.DetectFileFormat(filename)
		Debug.Print(String.Format("The message format is: {0}", info.FileFormatType.ToString))
		Dim _loadoptions As LoadOptions = Nothing

		Select Case info.FileFormatType
			Case Aspose.Email.FileFormatType.Eml
				_loadoptions = New EmlLoadOptions
			Case Aspose.Email.FileFormatType.Emlx
				_loadoptions = New EmlxLoadOptions
			Case Aspose.Email.FileFormatType.Msg
				_loadoptions = New MsgLoadOptions
			Case Aspose.Email.FileFormatType.Tnef
				_loadoptions = New TnefLoadOptions
		End Select
		mm = MailMessage.Load(filename, _loadoptions)
		message = Mapi.MapiMessage.FromMailMessage(mm)
		Debug.Print(String.Format("{0}Subject : {1}", vbNewLine, message.Subject))
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_CREATION_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CREATION_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_EXPIRY_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_EXPIRY_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_LAST_MODIFICATION_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_LAST_MODIFICATION_TIME)).ToUniversalTime))
		End If
		If message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME) IsNot Nothing Then
			Debug.Print(String.Format("PR_CLIENT_SUBMIT_TIME : {0:u}", CDate(message.GetPropertyDateTime(Mapi.MapiPropertyTag.PR_CLIENT_SUBMIT_TIME)).ToUniversalTime))
		End If
		If IsDate(message.DeliveryTime) AndAlso (Year(message.DeliveryTime) > 1900 And Year(message.DeliveryTime) < 3000) Then
			Debug.Print(String.Format("DeliveryTime : {0:u}", CDate(message.DeliveryTime).ToUniversalTime))
		End If
	Catch ex As Exception

#If DEBUG Then
Stop
#End If
End Try

End Sub

Debug output:

Loading eMail Using Badway
The message format is: Msg

Subject : Cavell Energy Corporation(Aspose.Email Evaluation) ???
PR_CREATION_TIME : 2018-07-05 13:39:38Z
PR_LAST_MODIFICATION_TIME : 2018-07-05 13:39:38Z
PR_CLIENT_SUBMIT_TIME : 2001-10-30 20:01:00Z
DeliveryTime : 2001-10-30 20:01:00Z

Why does it say “Aspose.Email Evaluation”? Since the license loaded ok.

I did find what is causing the problem.
When I use these 2 lines (from Badway)
mm = MailMessage.Load(filename, _loadoptions)
message = Mapi.MapiMessage.FromMailMessage(mm)
It produces bad dates
When I use these 2 lines (from Goodway)
message = Mapi.MapiMessage.FromFile(filename)
mm = message.ToMailMessage(Conv_opt)
It’s good

Why???

@elumicor,

We have logged this behavior as EMAILNET-39037 for further investigation at our end and will update you here once there is further information available in this regard.