Using Outlook object model from SharePoint Event receiver code RRS feed

  • General discussion

  • Hello Sir\Madam,

    I am working for Microsoft as a vendor. I am trying to send email from SharePoint event receiver by using Outlook Object Model "Microsoft.Office.Interop.Outlook".

    I am using Visual Studio 2012 and Outlook 2010 SP1.

    I am using below code -







    Applicationapplication = null;



    // Check whether there is an Outlook process running.


    if(Process.GetProcessesByName("OUTLOOK").Count() > 0)



    // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.

                        application =

    Marshal.GetActiveObject("Outlook.Application") asMicrosoft.Office.Interop.Outlook.Application;




    // If not, create a new instance of Outlook and log on to the default profile.

                        application =



    NameSpacenameSpace = application.GetNamespace("MAPI");


    "", "", Type.Missing, Type.Missing);


    //nameSpace = null;


    // Return the Outlook Application object.



    Issue is - after Namespace.logon, program just gets hung. I noticed that there is outlook process under taskmanager but that is only shown when "Show processes from all users" is checked.

    When I execute the same code from sample console application, it runs without any issue. Also outlook process is seen under task manager under user. here it is not required to check "Show processes from all users".

    Appreciate your help.


    Thursday, October 16, 2014 12:43 PM

All replies

  • Hello,

    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.

    You may consider using any third-party components or using low-level code - Extended MAPI which can be used from a Windows service.

    BTW Also I have noticed that you don't have the latest updates for Outlook 2010 installed.

    Thursday, October 16, 2014 12:52 PM
  • Thanks Eugene.

    I continued to debug further about the comexception issue. I analyzed that worker process under which SharePoint event receiver code executes is running under administrator mode. because of this when outlook is opened programmatically it also gets opened under admin mode. do you know if there is any way I can restrict outlook not to open in "Administrator mode". (Note - In compatibility settings, I have not selected run under Admin mode.)

    Snapshot 1 when outlook is created programmatically on server through console application.

    Snapshot 2 when outlook is created programmatically on server through Event Receiver code. Note - here it gets opened in Admin mode. I want to restrict it to open in non-admin mode.

    Appreciate any pointers.

    Paresh Gujar

    Friday, October 17, 2014 1:38 PM
  • The Outlook/Office extensibility model doesn't provide anything for that.
    Friday, October 17, 2014 7:12 PM