Search code examples
c#outlookvstooutlook-addinoffice-addins

How to check if outlook email encrypted?


I use Outlook 2016 from Office 2016. I develop VSTO Outlook plugin which upload email to the database (initially it save it as temp file on the hard drive). How to check if email is encrypted? How to check if email Signed? See first image which show how user encrypt it.

Note: when recieve and decrypte email, it appears "normal", not decrypted. But other users can't open saved email, see second image with message "Your Digital ID name cannot be found by the underlying security system." Currently there is not task to decrypt emails, only not to add encrypted in the system. Thank you.

if (item is Outlook.MailItem)
{
    var mailItem = item as Outlook.MailItem;
    // Check
    //if (mailItem.IsEncrypted) ...   // Here I need help
    //   show user warning and exit 
    mailItem.SaveAs(tmpEmailFile);
    ...

enter image description here

enter image description here


Solution

  • Use the PR_SECURITY_FLAGS property which is available in Extended MAPI (a low-level API on which Outlook is based on). The PropertyAccessor.GetProperty can help with retrieving the property value. The DASL name of the property is "http://schemas.microsoft.com/mapi/proptag/0x6E010003". The value can be one of the following constants:

    Value Const Description
    NONE 0x0000 Message has no security
    ENCRYPTED 0x0001 Message is encrypted
    SIGNED 0x0002 Message is signed
    SIGNED & ENCRYPTED 0x0003 Message is signed and encrypted

    See Outlook 2016 VB.NET Sign and Encrypt Message for more information.