'Log incoming and outgoing emails using Outlook web add-in

I have a working VSTO COM based Outlook add-in that intercepts all incoming/outgoing emails on a desktop outlook which is then used to save the details of the email into a SQL database. Below is a brief description of the steps I take using the add-in:

  1. Intercept an incoming/outgoing email and adds a custom GUID as a user property on the email
  2. Calls an end-point to my custom Web API on the cloud and sends an XML with details like the GUID (saved above) and other mail related ids and details
  3. The API end-point saved the details into a SQL database and returns the response back to Outlook so that Outlook doesn't freeze up
  4. A windows service runs in the background and monitors this SQL database for email items and makes a Web API call to Exchange or Office 365 to find the email using the GUID user property and then save it where needed.

I cannot save the email directly via the API call from VSTO add-in since there is some custom time-consuming logic that happens in the API so I cannot keep Outlook frozen for that time.

Is it possible to create something similar using the newer Outlook Web Add-in?



Solution 1:[1]

Kind of - you can intercept outgoing messages, but if you do, your addin won't be eligible to be published in the store.

It is still much easier in a VSTO addin. You cannot access Outlook Object Model from a secondary thread, but you can still run your code that does other things. Once you are done, you can access OOM on the main thread by opening message that you need to process by its entry id saved before you started the secondary thread. Note that the inability to access various objects from a secondary thread is OOM specific - Extended MAPI objects can be accessed from secondary threads, but Extended MAPI requires C++ or Delphi. In other languages (including all .Net languages), you can use Redemption (I am its author) and its RDO family of objects - all you need to do is save the value of the Application.Session.MAPIOBJECT property in a dedicated variable, then on a secondary thread create an instance of the RDOSession object and set its MAPIOBJECT property to the variable you saved on the main thread (see http://www.dimastr.com/redemption/faq.htm#Threads for more details).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1