Modify background color of MailItem in Outlook 2013 Inbox

1.6k views Asked by At

Is there a way to modify the background color in Outlook inbox listing of e-mails (MailItem instances) programmatically? I'd like to create an add-in that will allow me to color-code my emails according to some rules.

I've went through MailItem properties in the documentation, but wasn't able to find anything display-format related.

1

There are 1 answers

2
Eugene Astafiev On

The MailItem class doesn't provide anything for that. Instead, you need to customize the view in Outlook.

You can use the CurrentView property of the Folder or Explorer class to get a View object representing the current view. To obtain a View object for the view of the current Explorer, use Explorer.CurrentView instead of the CurrentView property of the current Folder object returned by Explorer.CurrentFolder.

The View object allows you to create customizable views that allow you to better sort, group and ultimately view data of all different types. There are a variety of different view types that provide the flexibility needed to create and maintain your important data.

  • The table view type (olTableView) allows you to view data in a simple field-based table.
  • The Calendar view type (olCalendarView) allows you to view data in a calendar format.
  • The card view type (olCardView) allows you to view data in a series of cards. Each card displays the information contained by the item and can be sorted.
  • The icon view type (olIconView) allows you to view data as icons, similar to a Windows folder or explorer.
  • The timeline view type (olTimelineView) allows you to view data as it is received in a customizable linear time line.

Views are defined and customized using the View object's XML property. The XML property allows you to create and set a customized XML schema that defines the various features of a view.

 Private Sub FormatHandoffMessages() 
   Dim objView As TableView 
   Dim objRule As AutoFormatRule 
   ' Check if the current view is a table view. 
   If Application.ActiveExplorer.CurrentView.ViewType = olTableView Then 
     ' Obtain a TableView object reference to the current view. 
     Set objView = Application.ActiveExplorer.CurrentView 
    ' Create a new rule that displays any message with a 
    ' subject line that starts with "HANDOFF" in 
    ' blue, bold, 8 point Courier New text. 
    Set objRule = objView.AutoFormatRules.Add("Handoff Messages") 
    With objRule 
      .Filter = """http://schemas.microsoft.com/mapi/proptag/0x0037001f""" & _ 
      " CI_STARTSWITH 'HANDOFF'" 
      With .Font 
        .Name = "Courier New" 
        .Size = "8" 
        .Bold = True 
        .Color = olColorBlue 
      End With 
    End With 
    ' Save and apply the table view. 
    objView.Save 
    objView.Apply 
  End If 
End Sub