Introduction
Outlook automation has become integral part of any LOB application. MS Excel, work, outlook are getting used by most of the enterprise applications today. This article provides quick view on how to integrate outlook with .net application.
In this example we will create a button in outlook on click of that button it will execute a method in an application.
Steps to create outlook project:
-
Click on new project.
-
Select "Office" as project type
-
Select "Office 2007 Add in" template from right side pane.
-
Enter name of the addin and path for the project; click on Ok
-
Visual Studio will create "ThisAddIn.cs" file for you.
-
Write below code snippet in the ThisAddIn_Startup.
a. Generate command bar.
b. Generate command button.
Steps to create .net Application
-
Open Visual Studio. Click on File->New->Project
-
Select Windows from left pane.
-
Select Windows Forms application from right pane.
-
Enter name and location of project
-
Click on Ok.
-
Below code snippet shows how to create remotable object.
a. Code snippet for IRemoteObject
b. Code snippet for RemoteObject
-
Below code snippet show how to create remote server to listen request from outlook
-
Add a new window form with a button in the same project. Set caption of the form as Server and button caption as "Start Server".
-
In the button click write below code.
Steps to integrate with .net application
-
In ThisAddin.cs file we created defination for _myButton _Click. Write below lines of code in the defination.
Steps to install Outlook application
-
In the same instance of Visual Studio of outlook project. Click on File->New->Project
-
Select "Setup and Deployment" under "Other Project Type" from left pane.
-
Select "Setup Project" from right pane.
-
In "File System Editor" select "Application folder" from left pane.
-
Right click on "Application folder" and select Add->Project Output.
-
In the "Add Project Output group" window select Outlook project.
-
Select "Primary Output" from below list box.
-
Click on Ok
-
Outlook project output and related dependent files will get added in the Application folder.
-
Build the setup project.
-
Navigate to the output folder of the setup project and run setup.exe
-
After the completion of setup start MS Outlook
-
You must see button gets added in the tool bar.
Now run your windows form application and start server by clicking on the "Start Server" button.
Click "Click Me" button on MS Outlook , you must get message "Call from outlook".