none
Outlook 2016 VB.NET Sign and Encrypt Message RRS feed

  • Question

  • I am trying to create a button in create new message that when clicked will do the same as manually putting a tick in "Encrypt message contents and attachments" and "Add digital signature to this message"

    Have been searching but have failed to find anything that is for Outlook 2016 and works.

    Please help.

    Saturday, February 4, 2017 12:24 PM

All replies

  • Hello,

    In the button event handler you may set a Boolean flag which indicates whether a message should be encrypted/signed or not. For example, you may create a toggle button on the ribbon. The value can be kept in a user property.

    You need to handle the ItemSend event where you can set all the required security flags (VBA code):

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
       If MsgBox("Add signature and encryption using the object model?", vbYesNo) = vbYes Then
          Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
          Dim oProp As Long
          oProp = CLng(Item.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))
          ' You can use this to verify the property's flag compared to
          ' what was set in Outlook.
          Debug.Print "Original flag value is: " & oProp
          uFlags = 0
          ulFlags = ulFlags Or &H1 ' Add the encrypted flag
          ulFlags = ulFlags Or &H2 ' Add the signed flag
          Item.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags
          Debug.Print "Updated flag value is: " & ulFlags
       End If
    End Sub

    Instead of displaying a dialog you can check out the user property value. As you see you need to modify  PR_SECURITY_FLAGS property (DASL name is http://schemas.microsoft.com/mapi/proptag/0x6E010003).


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Saturday, February 4, 2017 8:30 PM
  • Think this is basically the same as one of the Scripts I have already found and Visual Studio doesn't seem to like it.
    Sunday, February 5, 2017 12:14 PM
  • Hi,

    Do you get any error if the code above does not work for you? What is the exception?


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 6, 2017 6:20 AM
    Moderator
  • and Visual Studio doesn't seem to like it.

    Could you please be more specific? Do you get any errors or warnings in  VS?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, February 6, 2017 7:49 AM