none
Monitor Outlook Mailbox RRS feed

  • Question

  • Hi,

    I need to build a windows service that will monitor outlook mailboxes. The mailboxes are used on different PCs. Is it possible to run a centralised service from one server that can monitor all mailboxes?

    My code below works on my own PC where I have outlook installed and a 'development' folder added. How would I update this to work as a centralised service?

            Outlook.NameSpace outlookNameSpace;
            Outlook.MAPIFolder inbox;
            Outlook.Items items;
            Outlook.Application outlookApp;
    
    outlookApp = new Outlook.Application();
    outlookNameSpace = outlookApp.GetNamespace("MAPI");
    
    inbox = outlookNameSpace.Folders["development"].Folders["Inbox"];
    
    foreach (Microsoft.Office.Interop.Outlook.MailItem mailItem in inbox.Items)
                {
       double mins = (DateTime.Now - mailItem.CreationTime).TotalMinutes;
       if (mins > 10) 
       {
           MessageBox.Show(string.Format("Accounts: {0}", mailItem.Body));
       }
    }

    Thanks!


    • Edited by obrienkev Monday, May 25, 2015 9:54 AM
    Monday, May 25, 2015 9:53 AM

Answers

  • Hello,

    Outlook is just a client application. You will be able to monitor profiles configured in Outlook only. Anyway, the Considerations for server-side Automation of Office article states the following:

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    As a workaround you may use a low-level API from a Windows service - Extended MAPI, or any other third-party wrapper around that API (such as Redemption).

    It looks like you need to monitor the back-end software (the real mailbox) instead. If you use an Exchange profile in Outlook consider using EWS (Exchange Web Services) instead. See EWS Managed API, EWS, and web services in Exchange for more information. 

    Monday, May 25, 2015 10:39 AM

All replies

  • Hello,

    Outlook is just a client application. You will be able to monitor profiles configured in Outlook only. Anyway, the Considerations for server-side Automation of Office article states the following:

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    As a workaround you may use a low-level API from a Windows service - Extended MAPI, or any other third-party wrapper around that API (such as Redemption).

    It looks like you need to monitor the back-end software (the real mailbox) instead. If you use an Exchange profile in Outlook consider using EWS (Exchange Web Services) instead. See EWS Managed API, EWS, and web services in Exchange for more information. 

    Monday, May 25, 2015 10:39 AM
  • If your code is not running in a service, you can open other user's folder (assuming the current user has the right permissions) using Namespace.GetSharedDefaultFolder.

    As Eugene mentioned, you can use EWS (any language) or Extended MAPI (C++ or Delphi). You can also use Redemption (which wraps Extended MAPI) in any language - its RDO family of objects can be used in a service. Use RDOSession.LogonHostedExchangeMailbox (Exchange 2010 and up) to connect to the primary user's mailbox, then open other users' mailbox using RDOSession.GetSharedMailbox.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, May 26, 2015 12:23 AM