Mirza
Mirza

Reputation: 21

Can i add custom icon to "outlook" item?

I am trying to add a custom icon to outlook items (inbox items list) using officejs addon for outlook.

enter image description here

If this is not possible with officejs then how can I achieve this using Exchange service or with any other tool or library?

Upvotes: 2

Views: 1681

Answers (2)

darbid
darbid

Reputation: 2721

You can change the icon, however, you have a choice of icons. You would need to use C# or VB.NET (eg VSTO Outlook-addin) or VBA.

I could not find a list of icon values you can use but here is an image of an old list - in case the link gets lost.

Outlook Icons and values

Source of the image and also partly answering your question.

To change the icon you need to use the MailItem.PropertyAccessor

Couple of Examples Const (these are hex values but you can use a Long as well)

Const OL_PHONE = &H15D
Const OL_GROUP = &H202
Const OL_NOTE = &H1BD
Const PR_ICON_INDEX As String = "http://schemas.microsoft.com/mapi/proptag/0x10800003"

Using the below helper methods

'use the Get to see the value of an icon
'prior to this code you would need to get a reference to an Outlook mailitem
Dim res As New Object
GetExtendedPropertyValue(oMailItem, PR_ICON_INDEX, res)
'check the value of res or call Hex(res) to see its hex value

'here you can set the icon eg OL_GROUP etc
SetExtendedPropertyValue(oMailItem, PR_ICON_INDEX, OL_PHONE)

Couple of helper methods I have made

Private Function GetExtendedPropertyValue(ByVal aMailItem As Outlook.MailItem, ByVal aProperty As String, ByRef res As Object) As Boolean

    Dim oPropAcc As Outlook.PropertyAccessor = Nothing

    Try
        oPropAcc = DirectCast(aMailItem.PropertyAccessor, Outlook.PropertyAccessor)
        res = oPropAcc.GetProperty(aProperty)

        Return True

    Catch ex As System.Exception
        'Put your own logging here
    Finally
        If Not oPropAcc Is Nothing Then
            Marshal.ReleaseComObject(oPropAcc)
            oPropAcc = Nothing
        End If
    End Try
    Return False
End Function

Private Function SetExtendedPropertyValue(ByVal aMailItem As Outlook.MailItem, ByVal aProperty As String, ByVal value As Integer) As Boolean
    Dim oPropAcc As Outlook.PropertyAccessor = Nothing
    Try
        oPropAcc = DirectCast(aMailItem.PropertyAccessor, Outlook.PropertyAccessor)
        oPropAcc.SetProperty(aProperty, value)

        Return True
    Catch ex As System.Exception
        'Put your own logging here
    Finally
        If Not oPropAcc Is Nothing Then
            Marshal.ReleaseComObject(oPropAcc)
            oPropAcc = Nothing
        End If
    End Try
    Return False
End Function

These three examples look like this

example of the changed icons

The PR_ICON_INDEX PidTagIconIndex Canonical Property can be found here and note that they do say

This property, if it exists, is a hint to the client. The client may ignore the value of this property.

However this does not seem to be the case.

Of course the icon change will not be permanent. If the user forwards the emails or replies then it would be changed.

EDIT By the way here is a nice way to find out the possible icons. Make a temp folder and copy a rubbish email into this folder 2048 times. Then run this code

Public Sub PrIconIndex() 

USE THIS MACRO WITH CARE! 

Dim objItems As Items 
Dim mail As MailItem 
 Dim i As Integer 

Set objItems = Application.ActiveExplorer.CurrentFolder.Items 

For i = 1 To 2048 
    Set mail = objItems(i) 

    Call mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", i) 

    mail.Body = CStr(i) 
    mail.Save 
Next 

End Sub 

The above come from this forum link

Upvotes: 2

user7823505
user7823505

Reputation:

Currently the feature to add a custom icon to outlook items is not there. We track Outlook add-in feature requests on our user-voice page. Please add your request there. Feature requests on user-voice are considered, when we go through our planning process.

Upvotes: 0

Related Questions