I've been trying for countless hours and I can't figure it out. I have the below code for a UserForm in Excel. Everything runs as it should except that it refuses to actually encrypt the email. Anybody able to help?
Code:
Private Sub Submit_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim VEmail As Variant
Dim TEmail As Variant
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
VEmail = Application.WorksheetFunction.VLookup(vendor.Value, Worksheets("Sheet1").Range("A:D"), 3, False)
TEmail = Application.WorksheetFunction.VLookup(vendor.Value, Worksheets("Sheet1").Range("A:D"), 4, False)
On Error Resume Next
With OutMail
Const PR_SECURITY_FLAGS = "[URL]http://schemas.microsoft.com/mapi/proptag/0x6E010003[/URL]"
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
.To = VEmail
.CC = TEmail
.Subject = "C Number: " + Me.cnumber.Value + "/ R Number: " + Me.rnumber.Value + "/ B State: " + Me.bstate.Value + "/ Reason: " + Me.reason.Value
.HTMLBody = Me.message.Value & .HTMLBody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub