My Photo

Technical Architect with over 20 years experience in a wide range of technologies.


rss feed

Outlook add-in to unlock blocked attachments in .Net | Wednesday, April 09, 2008


By default Microsoft Outlook is configured to block specific file attachments based on file extensions. This is useful in most scenarios to prevent the spread of email viruses and to keep your pc secure. However sometimes you may want to override this behaviour in order to open attachments from known sources which are otherwise inaccessible. For a list of blocked file extensions see here.

For some reason the standard edition of Microsoft Outlook does not allow users to configure or disable these security settings, though it is possible to control behaviour by tweaking the registry.

The .Net forms application included in this article is an example application built on the Automation and Extensibility framework, which allows the registry settings to be controlled via an Outlook add-in. This adds an additional tab to the Options menu of Outlook and allows security settings to be adjusted for custom behaviour.


The attachment security features within Microsoft Outlook are controlled via two string registry keys, Level1Add and Level1Remove. These keys can be added at the following location, and allow the default behaviour for blocking attachments to be overridden.

    Note: 10.0 will vary depending on the version installed

When added, each key represents a list of semi-colon separated file extensions to either block (Level1Add) or unblock (Level1Remove). Security can be further customised with further keys for level2 security settings, however this is beyond the scope of this article.

Outlook Unlocker

The OutlookUnlocker add-in is installed by running the Setup.exe. This adds an Attachment Unlocker tab to the Options menu within Outlook, which can be accessed via the tools menu. Enter extensions to be blocked or unblocked into the blocked/unblocked lists accordingly. Do this by typing text into the relevant input box and pressing Enter.

Once the extension is added it can be moved to the blocked or unblock lists by highlighting the item and using the < and > arrows. Items can be removed from blocked and unblocked lists by highlighting an item and using the X button. Extensions not listed revert to the default Outlook behaviour for those extension types. You will need to restart Outlook for changes to take effect.

How it works

The solution was built on top of the Automation and Extensibility framework using the Visual Studio Shared Add-in project template for .Net. This creates an add-in template project, as well an installation project for installing the add-in.

In brief the extensibility framework allows managed .Net assemblies to communicate with unmanaged Com code via proxy (shim) objects. This allows IDE's such as Outlook to raise events which the add-ins can respond to in order to integrate with the application; such as when they are loaded or unloaded. The interface IDTExtensibility2 is commonly used for this purpose to hook into the application events.

The Outlook Unlocker solution consists of a class named Connect. This is the implementation of the IDTExtensibility2 interface created by the project template. In order to hook an additional tab to the Options menu we must register for the OptionsPagesAdd event as follows during the OnConnection event:

    // On connection register for the OptionsPagesAdd event
    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        Microsoft.Office.Interop.Outlook.Application applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
        applicationObject.OptionsPagesAdd += new ApplicationEvents_11_OptionsPagesAddEventHandler(applicationObject_OptionsPagesAdd);
    // When the OptionsPagesAdd is fired, add the custom property page 
    private void applicationObject_OptionsPagesAdd(PropertyPages Pages)
        Pages.Add(new Unlocker(), "Attachment Unlocker");

When the OptionsPagesAdd event is fired, the custom usercontrol named Unlocker is added to the Pages collection. The control implements an interface derived from a reference to the Microsoft.Office.Interop.Outlook assembly, which allows the control to act as a tab within the Options menu of Outlook.

With the custom control added, the implementation of the Unlocker usercontrol uses standard .Net behaviour to interact with the user and perform read/write functionality on the registry; thus controlling the security behaviour.


  • Initial release, April 2008

Further reading

No comments:

Post a Comment