none
New Outlook mail message doesn't load

    Question

  • Hi,

     I have the following simplified code:

    using Outlook = Microsoft.Office.Interop.Outlook;
    protected void SendEmailBtn_Click(object sender, EventArgs e)
            {
                            Outlook.Application OutlookApp = new Outlook.Application();
                Outlook.MailItem mailItem = (Outlook.MailItem)OutlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.Subject = "Test Send Email";
                mailItem.BCC = "test@test.com";
                mailItem.Body = "Dear";
                mailItem.Display(false);
            }

    I've installed office 2007 and 2007 PIAs and deployed the code on the server (win2008 server), but when I click on the send button nothing happens on the clients machine the outlook mail message is not created, the page just stays in a loading state, no errors or exceptions are given.  Looking at task manager on the server the outlook process does start and is running.  The code works fine locally i.e. an outlook mail  message is created.  I'm not sure what could be causing this to happen, could it be the anti virus on the server blocking file access? Do I need to install something else?  Any help would be much appreciated.  Thanks.

    • Edited by C_Shooter Thursday, September 27, 2012 10:29 AM formating
    Thursday, September 27, 2012 10:25 AM

Answers

  • That is correct. If you want your code to work on the client it must run on the client. In addition, using the Outlook object model from a Web application is not supported.
     
    I have no idea what your code is intended for use with, I can't read minds. It won't work as you've designed it though. Outlook code must run on the client.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "C_Shooter" <=?utf-8?B?Q19TaG9vdGVy?=> wrote in message news:3c881eb3-c43c-441c-9c91-682f610fb6fd...

    So your saying i am unable to create a new outlook mail messages on the clients machine from my web application, even if the client has outlook installed. 

    Is my code only intended for use with windows forms?


    Ken Slovak MVP - Outlook
    • Marked as answer by C_Shooter Thursday, September 27, 2012 4:41 PM
    Thursday, September 27, 2012 4:34 PM

All replies

  • Where is the code running, and where is the mail item supposed to open?
     
    If you have Outlook running on a server I hope you aren't trying to run it unattended or from a service or from a scheduler, none of those scenarios are supported at all.
     
    If Outlook is installed and running on a server it will only create new messages on the server, in that Outlook. It cannot create messages on client machines from code on the server, if that's what you want. It won't work at all. To create new messages on the client machines you need Outlook installed there and to run the code in those Outlook instances on the client machines.
     
    FWIW, I would add a logon as you're running out of process with Outlook:
     
    Outlook.Application OutlookApp = new Outlook.Application();
    Outlook.NameSpace oNS = OutlookApp.GetNameSpace("MAPI");
    oNS.Logon("", "", System.Reflection.Missing.Value, System.Reflection.Missing.Value);

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "C_Shooter" <=?utf-8?B?Q19TaG9vdGVy?=> wrote in message news:bdc6d2e2-8563-4528-ac59-e495bb43a0a3...

    Hi,

     I have the following simplified code:

    using Outlook = Microsoft.Office.Interop.Outlook;
    protected void SendEmailBtn_Click(object sender, EventArgs e)
            {
                            Outlook.Application OutlookApp = new Outlook.Application();
                Outlook.MailItem mailItem = (Outlook.MailItem)OutlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.Subject = "Test Send Email";
                mailItem.BCC = "test@test.com";
                mailItem.Body = "Dear";
                mailItem.Display(false);
            }

    I've installed office 2007 and 2007 PIAs and deployed the code on the server (win2008 server), but when I click on the send button nothing happens on the clients machine the outlook mail message is not created, the page just stays in a loading state, no errors or exceptions are given.  Looking at task manager on the server the outlook process does start and is running.  The code works fine locally i.e. an outlook mail  message is created.  I'm not sure what could be causing this to happen, could it be the anti virus on the server blocking file access? Do I need to install something else?  Any help would be much appreciated.  Thanks.


    Ken Slovak MVP - Outlook
    Thursday, September 27, 2012 2:16 PM
  • So your saying i am unable to create a new outlook mail messages on the clients machine from my web application, even if the client has outlook installed. 

    Is my code only intended for use with windows forms?

    Thursday, September 27, 2012 3:43 PM
  • That is correct. If you want your code to work on the client it must run on the client. In addition, using the Outlook object model from a Web application is not supported.
     
    I have no idea what your code is intended for use with, I can't read minds. It won't work as you've designed it though. Outlook code must run on the client.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "C_Shooter" <=?utf-8?B?Q19TaG9vdGVy?=> wrote in message news:3c881eb3-c43c-441c-9c91-682f610fb6fd...

    So your saying i am unable to create a new outlook mail messages on the clients machine from my web application, even if the client has outlook installed. 

    Is my code only intended for use with windows forms?


    Ken Slovak MVP - Outlook
    • Marked as answer by C_Shooter Thursday, September 27, 2012 4:41 PM
    Thursday, September 27, 2012 4:34 PM