One with developing code for messaging development is to have code run when a specific event happens. Each mailbox API has its own ways of handling calls. Below is an overview of APIs and other mechanisms which support events on the mailbox.
Exchange Web Services (EWS):
Exchange Web Service notifications are widely used and has several models for notifications. Be sure to read-up on each notification methodology to find which is best for your application. Your code should be written to handle Exchange related throttling and the possible errors which might be thrown. When going against Exchange 2010, 2013 and Exchange Online its extremely important to write your code to support affinity.
Notification subscriptions, mailbox events, and EWS in Exchange
How to: Maintain affinity between a group of subscriptions and the Mailbox server in Exchange
Handling notification-related errors in EWS in Exchange
Mailbox synchronization and EWS in Exchange
EWS throttling in Exchange
REST for Exchange Online:
REST calls go directly against Exchange and the calls can be done from any client.
Outlook Notifications REST API reference (preview)
About: 365 REST APIs
Outlook Object Mode (OOM):
Outlook Object Model can be used in several ways. First, there is Outlook in-application VBA support which will handle events. Outlook is extensible through custom add-ins and such add-ins run code off of events. An external application can also be written to handle mailbox events. Note that OOM code needs to be run with an interactive user present. So, its not suitable for things such as windows and web services or web pages or any other form of non-user monitored automation.
Working with Outlook Events
Using Events with Automation
OOM can also handle Outlook application events:
Outlook Object Model Overview
With .NET code some extra care needs to be taken with Outlook Object model:
OOM.NET blog POSTS
Mail apps for Outlook
With Exchange Online there is a new type of development for customizing OWA called Mail apps for Outlook and it can run code upon some events.
Mail apps for Outlook
Even though Extended MAPI is an extremely old messaging API it is still widely used today and it also does support code firing off of events. Note though that Extended MAPI must be written with unmanaged code such as C++.
Event Notification in MAPI
MAPI Notification Events
If you decide to go down the path of Extended MAPI then be sure to leverage this blog for information:
SGriffin’s MAPI Internals
Custom Exchange Transport Agents:
As mail flows through Exchange SMTP transport an Exchange transport agent can look at the stream and modify. Note that this only works with on premise Exchange servers and not Exchange Online. The events it works off of fire on messages before a message arrives in a mailbox and after its submitted. These agents are built with custom .NET code.
Reading and modifying messages in the Exchange 2013 transport pipeline
Creating transport agents for Exchange 2013
Transport agents in Exchange 2013
Here are some codeless options…
Exchange Transport Rules
Exchange has its own built in rule system for working with messages in transport – no coding required.
Data Loss Prevention (DLP):
DLP helps prevent incomplete messages or messages which violate policies from being sent. It is abilities are wired into Outlook, OWA, Windows phone and even the OWA apps for iOS and Android. No coding required.
Data Loss Prevention
Data loss prevention in Exchange just got better
Inbox rules don’t require coding and setting them up is pretty strait forward as a wizard is used. Custom code can also create rules.
Manage email messages by using rules
Note that in that EWS OOM and Extended MAPI can create inbox rules which can take action on items based-upon events:
Creating Inbox rules by using the EWS Managed API 2.0
MAPI Application: Create an Inbox rule to set the Sensitivity of messages with a specific message class to Private
Managing Rules in the Outlook Object Model
About: Messaging APIs