Events from mailbox activity
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
https://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx
How to: Maintain affinity between a group of subscriptions and the Mailbox server in Exchange
https://msdn.microsoft.com/EN-US/library/office/dn458789(v=exchg.150).aspx
Handling notification-related errors in EWS in Exchange
https://msdn.microsoft.com/EN-US/library/office/dn458788(v=exchg.150).aspx
Mailbox synchronization and EWS in Exchange
https://msdn.microsoft.com/en-us/library/office/dn440952(v=exchg.150).aspx
EWS throttling in Exchange
https://msdn.microsoft.com/en-us/library/office/jj945066(v=exchg.150).aspx
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)
https://msdn.microsoft.com/office/office365/APi/notify-rest-operations
About: 365 REST APIs
https://blogs.msdn.com/b/webdav_101/archive/2015/05/18/about-365-rest-apis.aspx
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
https://msdn.microsoft.com/en-us/library/office/ff865014.aspx
Using Events with Automation
https://msdn.microsoft.com/EN-US/library/office/ff866235.aspx
OOM can also handle Outlook application events:
Application events
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.application_events.aspx
Outlook Object Model Overview
https://msdn.microsoft.com/en-us/library/ms268893.aspx
With .NET code some extra care needs to be taken with Outlook Object model:
OOM.NET blog POSTS
https://blogs.msdn.com/b/mstehle/archive/tags/oom-net/
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
https://msdn.microsoft.com/en-us/library/office/fp161135.aspx
Extended MAPI:
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
https://msdn.microsoft.com/en-us/library/office/cc842079.aspx
MAPI Notification Events
https://msdn.microsoft.com/en-us/library/office/cc840027.aspx
If you decide to go down the path of Extended MAPI then be sure to leverage this blog for information:
SGriffin's MAPI Internals
https://blogs.msdn.com/b/stephen_griffin/
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
https://msdn.microsoft.com/en-us/library/office/aa579261(v=exchg.150).aspx
Creating transport agents for Exchange 2013
https://msdn.microsoft.com/en-us/library/office/bb204097(v=exchg.150).aspx
Transport agents in Exchange 2013
https://msdn.microsoft.com/en-us/library/office/dd877026(v=exchg.150).aspx
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.
Transport rules
https://technet.microsoft.com/en-us/library/dn271424(v=exchg.150).aspx
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
https://technet.microsoft.com/en-us/library/jj150527(v=exchg.150).aspx
Data loss prevention in Exchange just got better
https://blogs.technet.com/b/exchange/archive/2014/02/25/data-loss-prevention-in-exchange-just-got-better.aspx
Inbox rules:
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
https://support.office.com/en-sg/article/Manage-email-messages-by-using-rules-c24f5dea-9465-4df4-ad17-a50704d66c59
Inbox rules in Outlook Web App
https://support.office.com/en-sg/article/Inbox-rules-in-Outlook-Web-App-edea3d17-00c9-434b-b9b7-26ee8d9f5622?ui=en-US&rs=en-SG&ad=SG
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
https://msdn.microsoft.com/en-us/library/office/ff597938(v=exchg.80).aspx
MAPI Application: Create an Inbox rule to set the Sensitivity of messages with a specific message class to Private
https://blogs.msdn.com/b/emeamsgdev/archive/2012/12/04/mapi-application-create-an-inbox-rule-to-set-the-sensitivity-of-messages-with-a-specific-message-class-to-private.aspx
Managing Rules in the Outlook Object Model
https://msdn.microsoft.com/en-us/library/bb206763(v=office.12).aspx
Also see:
About: Messaging APIs
https://blogs.msdn.com/b/webdav_101/archive/2015/08/07/about-messaging-apis.aspx