How to: Verify an Attachment is Blocked

How to: Verify an Attachment is Blocked

This code sample in C++ shows how to use the IAttachmentSecurity interface to find out whether an attachment is blocked by Outlook for viewing and indexing.

IAttachmentSecurity is derived from the IUnknown interface. You can obtain the IAttachmentSecurity interface by calling IUnknown::QueryInterface on the MAPI session object, requesting IID_IAttachmentSecurity. IsAttachmentBlocked returns TRUE in pfBlocked if the attachment is considered unsafe by Outlook and is blocked for viewing and indexing in Outlook.

  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;

}