Bug in MailMessage date? Doesn't save date

(Aspose.Email .Net 21.1.1.0)

I load a msg, change the date and save it to a new filename, but the date of the saved msg is todays date when I open it in Outlook.

Here’s my simple test code:

Dim optLoad As New Aspose.Email.MsgLoadOptions
Dim d As New Date(2021, 1, 1)
Using msg As Aspose.Email.MailMessage = Aspose.Email.MailMessage.Load(srcPath, optLoad)
msg.Date = d.ToUniversalTime
msg.Save(dstPath, optSave)
End If
End Using

Is this a bug? … or is there another date property?

@Morajo

Can you please share the MSG file and share which date you want to change in the form of snapshot so that I may help you accordingly in this regard.

tmp5321.tmp.zip (1.7 KB)
screenshot.png (16.6 KB)

I need to set the “sent date”.

This is my Outlook addin test code, where I need to set sent date to january first 2021:

Dim dstPath As String = $"{Path.GetTempFileName}.msg"
Dim optLoad As New Aspose.Email.MsgLoadOptions
Dim d As New Date(2021, 1, 1)
Using msg As New Aspose.Email.MailMessage
	msg.Subject = "Test"
	msg.IsDraft = False
	msg.Sender = "noreply@mail.com"
	msg.To.Add("johndoe@mail.com")
	msg.HtmlBody = "This is just a test"
	msg.Date = d.ToUniversalTime
	Dim optSave As New Aspose.Email.MsgSaveOptions(Aspose.Email.MailMessageSaveType.OutlookMessageFormat)
	msg.Save(dstPath, optSave)
End Using

Dim mail As Outlook.MailItem = CType(Globals.ThisAddIn.Application.Session.OpenSharedItem(dstPath), Outlook.MailItem)
Dim forwardEmail As Outlook.MailItem = mail.Forward
forwardEmail.Display()
mail.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard)
Marshal.ReleaseComObject(mail)
mail = Nothing

… but in the screenshot the sent date is set to todays date.

Thanks.

@Morajo

I am checking this on my end and will get back to you with feedback as soon as possible.

@Morajo

Can you please try using following updated code sample on your end.

Dim dstPath As String = "/Users/mudassirkhan/Downloads/saved.msg"
Dim optLoad = New Aspose.Email.MsgLoadOptions()
Dim d = New DateTime(2021, 1, 1)

Using msg = New Aspose.Email.MailMessage()
    msg.Subject = "Test"
    msg.IsDraft = False
    msg.Sender = "noreply@mail.com"
    msg.[To].Add("johndoe@mail.com")
    msg.HtmlBody = "This is just a test"
    msg.[Date] = d.ToUniversalTime()
    Dim optSave = New Aspose.Email.MsgSaveOptions(Aspose.Email.MailMessageSaveType.OutlookMessageFormat)
    optSave.PreserveOriginalDates = True
    msg.Save(dstPath, optSave)
End Using