问题
I have a problem in my Outlook Addin. My AddIn processes the incoming mails and validates different headers etc. I want to check if a specific headers is set and then change the Icon of this mail in my inbox folder. Is this possible?
回答1:
You can either
change the icon to a couple dozen or so predefined icons used by Outlook itself (e.g. when it shows that a message was replied to/forwarded) by modifying the PR_ICON_INDEX MAPI property (DASL name
http://schemas.microsoft.com/mapi/proptag/0x10800003
) using MailItem.PropertyAccessor.SetProperty. You can play with that property and its different values in OutlookSpy - select a message with a replied/forwarded icon, click IMessage button, double click on the PR_ICON_INDEX MAPI property to modify it.Install your own custom form. You can specify the message class that the form handles and your custom icon. If you change the message class of a message, Outlook will show your custom icon.
回答2:
No, custom icons can be bu used with custom forms only. So, you need to publish a custom form to get the icon changed.
But you are free to handle the incoming emails. For example, you may handle the NewMailEx event of the Application class which is fired when a new item is received in the Inbox.
This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Note that this behavior has changed from earlier versions of the event when the EntryIDCollection contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired.
The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously.
You can use the PropertyAccessor.GetProperty method to get the PR_TRANSPORT_MESSAGE_HEADERS property value:
Sub DemoPropertyAccessorGetProperty()
Dim PropName, Header As String
Dim oMail As Object
Dim oPA As Outlook.PropertyAccessor
'Get first item in the inbox
Set oMail = _
Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
'PR_TRANSPORT_MESSAGE_HEADERS
PropName = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
'Obtain an instance of PropertyAccessor class
Set oPA = oMail.PropertyAccessor
'Call GetProperty
Header = oPA.GetProperty(PropName)
Debug.Print (Header)
End Sub
来源:https://stackoverflow.com/questions/31477432/change-inbox-icons-in-outlook-at-runtime