VBA macro to perform auto outlook email encryption based on user input while sending an outlook mail. This macro runs in the background when user clicks on send button.
What this macro does?
1. Checks whether the outlook mail is already encrypted manually by the sender
2. If the mail is already encrypted, then this macro doesn’t do anything. The mail just goes.
2. If the mail is not already encrypted and when user clicks on send button then it pop ups a confirmation window asking the user whether to encrypt (automatically) and send the mail or just send a non-encrypted mail
3. If the user clicks on “Yes” button, it adds encryption automatically and sends the encrypted mail.
4. If the user clicks on “No” button, it sends unencrypted message like a normal mail.
VBA macro code:
”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
Dim strSubject As String Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003" oProp = CLng(Item.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS)) Debug.Print "Original flag value is: " & oProp If oProp = 0 Then ' checking if the mail is already encrypted If MsgBox("This mail is not encrypted. Do you want to send the mail with auto encryption?", vbYesNo) = vbYes Then ulFlags = 0 ulFlags = ulFlags Or &H1 ' encrypt the mail Item.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags Debug.Print "Updated flag value is: " & ulFlags End If End If End Sub
”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””