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?
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.
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
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.