How to sign or encrypt a message programmatically from OOM


Q: How do I signal to Outlook to sign and / or encrypt a message from the Outlook object model?


A: There is not a first-class object or property to do this within the object model.  However, you can set the MAPI property PR_SECURITY_FLAGS.  The code below demonstrates this using the PropertyAccessor object:


Sub SignAndEncrypt()


    Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"


    Dim mi As MailItem


    Set mi = Application.ActiveInspector.CurrentItem


    Dim prop As Long


    prop = CLng(mi.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))


    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED


    ulFlags = ulFlags Or &H2 ' SECFLAG_SIGNED


    mi.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags


    Set mi = Nothing


End Sub

Comments (3)

  1. Nick L. says:

    This was a GREAT help to me! At my agency they are both ON by default. I needed to set both to OFF via Access VBA. After some experimentation I found it can be done by scrapping ulFlags and prop and chaging the SetProperty call to….

    objOutlookMsg.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, -4

    Note I'm also not DIM'ing or setting mi. I'm just using the objOutlookMsg object that's already set in my app. Anyway, thanks for posting this!

  2. aaa007 says:

    best method and shortest to get it done !!!

  3. Naveen says:

    Nick, your code is very useful. Thanks for sharing

Skip to main content