Click here to Skip to main content
15,884,849 members
Articles / Desktop Programming / Windows Forms

Outlook add-in to unlock blocked attachments in .NET

Rate me:
Please Sign up or sign in to vote.
3.50/5 (2 votes)
9 Apr 2008CPOL3 min read 38.7K   362   15   5
An Outlook add-in written in .NET which allows blocked file attachments to be unlocked.

Introduction

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 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.

Background

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
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\Security

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 more 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 the 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 unblocked lists by highlighting the item and using the < and > arrows. Items can be removed from the 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 as 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 IDEs 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:

C#
// 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.

History

  • Initial release, April 2008

Further reading

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
Mike Carlisle - Technical Architect with over 20 years experience in a wide range of technologies.

@TheCodeKing

Comments and Discussions

 
GeneralRuntime error loading Com Add-Ins Pin
C Is Sharp10-Aug-10 19:27
C Is Sharp10-Aug-10 19:27 
GeneralRe: Runtime error loading Com Add-Ins Pin
TheCodeKing11-Aug-10 9:03
TheCodeKing11-Aug-10 9:03 
GeneralRe: Runtime error loading Com Add-Ins Pin
C Is Sharp11-Aug-10 17:36
C Is Sharp11-Aug-10 17:36 
GeneralInstallation [modified] Pin
richardw4822-Apr-08 2:59
richardw4822-Apr-08 2:59 
GeneralRe: Installation Pin
TheCodeKing23-Apr-08 8:54
TheCodeKing23-Apr-08 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.