How to use the IAttachmentSecurity API to verify whether an attachment is considered to be blocked in Outlook

This article has been archived. It is offered "as is" and will no longer be updated.
Microsoft Office Outlook 2007 includes a feature that blocks attachments that are considered unsafe. Custom code can query to verify whether Outlook considers a particular attachment to be blocked. The code does this by using the IAttachmentSecurity API.

Blocked attachments

The attachments that are blocked by Outlook 2007 can vary from client to client. Which attachments are blocked depends on how Outlook 2007 is configured and on policies that the administrator has applied.

For more information about how Outlook blocks attachments, click the following article number to view the article in the Microsoft Knowledge Base:
829982 Cannot open attachments in Microsoft Outlook

The IAttachmentSecurity API exposes the IsAttachmentBlocked function. This function analyzes a file name. Then, the IsAttachmentBlocked function reports whether the file is considered to be blocked by Outlook. If the file is blocked, it is not shown in or indexed in Outlook 2007.

Definition of the IAttachmentSecurity API

DEFINE_GUID(IID_IAttachmentSecurity,			0xB2533636,			0xC3F3, 0x416f, 0xBF, 0x04, 0xAE, 0xFE, 0x41, 0xAB, 0xAA, 0xE2);#define MAPI_IATTACHMENTSECURITY_METHODS(IPURE) \MAPIMETHOD(IsAttachmentBlocked) \		(LPCWSTR pwszFileName, BOOL *pfBlocked) IPURE; DECLARE_MAPI_INTERFACE_(IAttachmentSecurity, IUnknown){    BEGIN_INTERFACE    MAPI_IUNKNOWN_METHODS(PURE)    MAPI_IATTACHMENTSECURITY_METHODS(PURE)};

Usage of the IAttachmentSecurity API

This interface can be obtained by calling the QueryInterface function on the MAPI session object, requesting IID_IAttachmentSecurity. IsAttachmentBlocked will return "true" in "pfBlocked" if the attachment is considered blocked by Outlook, and therefore is not shown in or indexed in Outlook 2007.
HRESULT IsAttachmentBlocked(LPMAPISESSION lpMAPISession, LPCWSTR pwszFileName, BOOL* pfBlocked){	if (!lpMAPISession || !pwszFileName || !pfBlocked) return MAPI_E_INVALID_PARAMETER;	HRESULT hRes = S_OK;	IAttachmentSecurity* lpAttachSec = NULL;	BOOL bBlocked = false;	hRes = lpMAPISession->QueryInterface(IID_IAttachmentSecurity,(void**)&lpAttachSec);	if (SUCCEEDED(hRes) && lpAttachSec)	{		hRes = lpAttachSec->IsAttachmentBlocked(pwszFileName,&bBlocked);	}	if (lpAttachSec) lpAttachSec->Release();	*pfBlocked = bBlocked;	return hRes;}// IsAttachmentBlocked
OL2007 Outlook2007

Article ID: 919199 - Last Review: 01/16/2015 09:19:12 - Revision: 1.2

  • Microsoft Office Outlook 2007
  • kbnosurvey kbarchive kbexpertiseinter kbinfo KB919199