I am trying to create a mail item in Outlook with old date and time, which looks some thing like an Inbox Mail Item which arrived long back. After some painful hours of searching and reading forums, 3rd party libraries, somehow, I got a solution to do this and would like to share it with you here.
Here you go!
Dim objPost As Outlook.PostItem
Dim objSafePost As Redemption.SafePostItem
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Const PR_ICON_INDEX = &H10800003
objNS = Application.GetNamespace(“MAPI”)
objInbox = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
objPost = objInbox.Items.Add(Outlook.OlItemType.olPostItem)
objSafePost = CreateObject(“Redemption.SafePostItem”)
objSafePost.Item = objPost
objSafePost.MessageClass = “IPM.Note”
‘ remove IPM.Post icon
objSafePost.Fields(PR_ICON_INDEX) = String.Empty
Catch ex As Exception
MessageBox.Show(“Error: ” & ex.ToString)
objSafePost = Nothing
objPost = Nothing
objInbox = Nothing
objNS = Nothing
- We have to create an instance of Outlook.PostItem instead of Outlook.MailItem.
- We can also do it using RDOMail which is much simpler than this. (I will discuss about this in separate post).
I have created the mail item with old date time stamps, attachments successfully. But, couldn’t reset the icon of the PostItem that is created. Searching for a solution to it . Will update it in this post once I got that.