none
Start outlook add-in from lync or external program RRS feed

  • Question

  • I have an Outlook add-in which is an add-in that when opened open a window, like pressing the "New email" button. There you can send a message to my server. What I want to do now is to integrate it into Lync. When you right click on a contact you get up the context menu and there you can select "Send an email message" and when pressing it will open up a window you can send a email to that Contact. So I want to create my own option in the menu (already done) and when clicking on it I want to open up a window with my addin.

    I have been searching quite a lot but with no success. All I have come up with is to be able to check if it exists. I suppose I am doing this totaly wrong...

    Application app = new Application();
                var myAddin = app.COMAddIns;
                var count = myAddin.Count;
                COMAddIn addin;
    
                for (int i = 1; i <= count; i++)
                {
                    addin = myAddin.Item(i);
                    if (addin.ProgId == "MyAddIn")
                    {
                        //Hoped to do something here..
                    }
                }

    Thanks,
    Ludwig

     
    Wednesday, October 24, 2012 1:24 PM

Answers

  • I don't understand the code you're using to start Outlook:
     
                _app = new Outlook.Application();

                Application app = new Application();
                var ns = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, true);


    What is app? What sort of Application, if not Outlook.Application?
     
    Why are you doing the login to NameSpace with the NewSession argument set to true? I said to set it to false.
     
    Additionally, you really shouldn't use new Outlook.Application() at all if Outlook is already running. You should instead grab an instance of the running Outlook.Application. Something like this:
     

    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

    int collCount = processes.Length;

    if (collCount != 0)

    {

        // Outlook already running, hook into the Outlook instance

        outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    }

    if (outlookApp == null)

    {

        // Outlook not already running, start it

        outlookApp = new Outlook.Application();

    }


    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Lullenn" <=?utf-8?B?THVsbGVubg==?=> wrote in message news:e831b7be-08e6-49a2-9f28-8f1ccfa8c2c2...

    My load behavior is set to 3 so it loads when staring Outlook.

    I have come a bit on the way but it does not work really as it should. If I have opened Outlook Before I try to start my code it is working. When I do not have it open it renders a bit of the view but as the add-in run some initialization in the ThisApp.cs file it does not work. I tried to do the init before rendering in the form init but it did not work as expected. One error I did get was that the init tries to populate a folder and I suppose that is not okay without having the Outlook main view open. Also the added ribbon was not shown.

    private void button1_Click(object sender, EventArgs e)
            {
                _app = new Outlook.Application();
    
                Application app = new Application();
                var ns = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, true);
    
    
                var o = app.CreateItem(OlItemType.olPostItem) as PostItem;
                o.MessageClass = "IPM.Post.SmsOut.1Way";
                o.BodyFormat = OlBodyFormat.olFormatPlain;
                o.Display();
            }


    Ken Slovak MVP - Outlook
    • Marked as answer by Lullenn Friday, October 26, 2012 11:37 AM
    Thursday, October 25, 2012 3:13 PM
    Moderator

All replies

  • Assuming that your "Application" object actually resolves to an Outlook.Application object, what is the LoadBehavior state of the addin registration in the Windows registry normally? Is it 2 or 3 or some other value? Doesn't your addin load and run when Outlook starts running?
     
    If your addin is not disabled but doesn't start with Outlook you can get the Connect Boolean property of your AddIn and set it to True to start the addin.
     
    If you are starting Outlook with new Application I would also get a NameSpace object (Application.GetNameSpace("MAPI") and then log into Outlook as your code is automating Outlook out-of-process.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Lullenn" <=?utf-8?B?THVsbGVubg==?=> wrote in message news:8434e800-4177-4258-bd92-b9689b4f02c0...

    I have an Outlook add-in which is an add-in that when opened open a window, like pressing the "New email" button. There you can send a message to my server. What I want to do now is to integrate it into Lync. When you right click on a contact you get up the context menu and there you can select "Send an email message" and when pressing it will open up a window you can send a email to that Contact. So I want to create my own option in the menu (already done) and when clicking on it I want to open up a window with my addin.

    I have been searching quite a lot but with no success. All I have come up with is to be able to check if it exists. I suppose I am doing this totaly wrong...

    Application app = new Application();
                var myAddin = app.COMAddIns;
                var count = myAddin.Count;
                COMAddIn addin;
    
                for (int i = 1; i <= count; i++)
                {
                    addin = myAddin.Item(i);
                    if (addin.ProgId == "MyAddIn")
                    {
                        //Hoped to do something here..
                    }
                }

    Thanks,
    Ludwig

     

    Ken Slovak MVP - Outlook
    Wednesday, October 24, 2012 2:34 PM
    Moderator
  • My load behavior is set to 3 so it loads when staring Outlook.

    I have come a bit on the way but it does not work really as it should. If I have opened Outlook Before I try to start my code it is working. When I do not have it open it renders a bit of the view but as the add-in run some initialization in the ThisApp.cs file it does not work. I tried to do the init before rendering in the form init but it did not work as expected. One error I did get was that the init tries to populate a folder and I suppose that is not okay without having the Outlook main view open. Also the added ribbon was not shown.

    private void button1_Click(object sender, EventArgs e)
            {
                _app = new Outlook.Application();
    
                Application app = new Application();
                var ns = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, true);
    
    
                var o = app.CreateItem(OlItemType.olPostItem) as PostItem;
                o.MessageClass = "IPM.Post.SmsOut.1Way";
                o.BodyFormat = OlBodyFormat.olFormatPlain;
                o.Display();
            }

    Thursday, October 25, 2012 11:39 AM
  • I don't understand the code you're using to start Outlook:
     
                _app = new Outlook.Application();

                Application app = new Application();
                var ns = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, true);


    What is app? What sort of Application, if not Outlook.Application?
     
    Why are you doing the login to NameSpace with the NewSession argument set to true? I said to set it to false.
     
    Additionally, you really shouldn't use new Outlook.Application() at all if Outlook is already running. You should instead grab an instance of the running Outlook.Application. Something like this:
     

    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

    int collCount = processes.Length;

    if (collCount != 0)

    {

        // Outlook already running, hook into the Outlook instance

        outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    }

    if (outlookApp == null)

    {

        // Outlook not already running, start it

        outlookApp = new Outlook.Application();

    }


    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Lullenn" <=?utf-8?B?THVsbGVubg==?=> wrote in message news:e831b7be-08e6-49a2-9f28-8f1ccfa8c2c2...

    My load behavior is set to 3 so it loads when staring Outlook.

    I have come a bit on the way but it does not work really as it should. If I have opened Outlook Before I try to start my code it is working. When I do not have it open it renders a bit of the view but as the add-in run some initialization in the ThisApp.cs file it does not work. I tried to do the init before rendering in the form init but it did not work as expected. One error I did get was that the init tries to populate a folder and I suppose that is not okay without having the Outlook main view open. Also the added ribbon was not shown.

    private void button1_Click(object sender, EventArgs e)
            {
                _app = new Outlook.Application();
    
                Application app = new Application();
                var ns = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, true);
    
    
                var o = app.CreateItem(OlItemType.olPostItem) as PostItem;
                o.MessageClass = "IPM.Post.SmsOut.1Way";
                o.BodyFormat = OlBodyFormat.olFormatPlain;
                o.Display();
            }


    Ken Slovak MVP - Outlook
    • Marked as answer by Lullenn Friday, October 26, 2012 11:37 AM
    Thursday, October 25, 2012 3:13 PM
    Moderator
  • Thank you! So thats how I should do it, Outlook now starts and I get a call to my ThisAddIn.cs startup! :D

    Friday, October 26, 2012 11:37 AM