Simple Outlook Add-in with VSTO 3.0
Creating add-ins with Visual Studio 2008 and VSTO 3.0 (Visual Studio Tools for Office) is easy and fast… Just use File –> New –> Project –> Select correct add-in i.e. Outlook 2007 Add-in and you project template is created. And you can run you add-in in debug by just hitting F5! So the basic setup is just few clicks and then you’re ready to start implementing your actual functionality i.e. extending ribbon etc.
In this post I’m going to create simple add-in that demonstrates how you can send emails on behalf of someone else and the selection for doing that is done automatically. Let’s go through the scenario since it’s easier to understand the functionality that way.
I have users John, Jane and Administrator. John wants to contact Jane but doesn’t know how to contact her so he sends out email to the administrator:
Administrator receives mail from John:
Since Administrator knows Jane’s home phone he can contact her in urgent matters and get her message back to John. In this case Administrator just presses Reply to John’s email and writes the message as Jane dictates it over the phone:
John receives email that appears to be written by Jane:
Okay that was our scenario and now let’s see how it was created.
Step 1: Well this is pretty obviously :-)
Step 2: Write following code (and as always.. use this at your own risk :-). This should be extended with better error handling, sanity checks etc.):
|
|
Code works so that we first trap events from ItemLoad (on line 11). In Application_ItemLoad we check that is this current item MailItem and if it is we then hook Open event of that Item. And when mail item is opened we’ll check that does that contain Jane at the subject. And if it does then we set the SentOnBehalfOfName property for the mail item. You need to modify contents between lines 37 and 41 to make this work in real life. I just made this as simple as possible. So probably adding few more checks isn’t bad idea :-)
Step 3: Build, Test and when everything is working then Publish:
Publishing wizard asks the location for the published files:
After that published location contains following files:
Setup.exe installs the add-in. Application Files folder contains subfolder for each version of the add-in (since it will be published to same location on update). You can actually control the check for new versions from VS (by default add-in checks for update once per week):
Now you can install the add-in for all the necassary users. Setup also knows about prerequisites (.NET framework 3.5 and VSTO 3.0 Runtime) and knows how to get them during install:
And when prereqs are ok we’re ready to install our app (this screenshot is from Windows Server 2003):
After the installation add-in can be seen in Add Remove Programs (and removed if needed):
Now your Outlook will work as described at the beginning of the post.
Hmm… you might start wondering that isn’t there few security issues in this approach? How can administrator act as Jane and how that isn’t displayed at his Outlook? Well by default security forbids this kind of scenario but if this kind of approach is needed then you need to give permission to the users at the AD (Important note: I gave Everyone permissions to “Send As” but that is not the way to go in real life):
And what does Outlook do then? In previous screenshots Outlook didn’t notify administrator about the SentOnBehalfOfName property change. However if you add more email addresses to your email then Outlook refreshes the view to this:
So Outlook added From… field and it now clearly indicates that this message will be send as Jane. Outlook just makes sure that user is aware of the senders change. Obviously our add-in could inform the end user with some kind of tooltip or something like that but I’ll leave those details to you.
Well here was small example of Outlook add-in. I’ll probably come back to add-ins in near future so stay tuned…
Anyways… Happy hacking!
J
Comments
Anonymous
October 08, 2008
Hi Janne, I see your using click-once and I know it is the prefered method, but I need to deploy my addin inside another MSI. So the question is do you have a procedure to create an MSI for a VSTO 3.0 Outlook addin created in Visual Studio 2008? I know it is not as simple as adding a deployment project to the solution. There is probably registry issues that has to be resolved. Thanks, DawieAnonymous
April 14, 2009
Hi Janne, Thanks for sharing this. I made an Add-In (based on your code) to change the Reply To address to a distribution group. Thanks, JonasAnonymous
May 28, 2009
Hi Janne, It gave me good start. Thanks,Anonymous
November 30, 2009
Hi Jane, Thanks for the info. I would like to know if there is a designer for designing my addin Thanks SujayAnonymous
September 08, 2010
Hi, Tanks for your useful post. and please provide me url where i can download VSTO for VS2008Anonymous
March 12, 2016
Please I am interestedAnonymous
August 08, 2016
Hi,Thanks for the post.I've installed outlook 2016 and visual studio 2015 in my machine.I followed the above procedures to an add-in but it is not working as expected.What'd be the problem?Any help would be greatly appreciated.Regards,Hussain Badusha.