Programmatically encrypt email (2010)

Status
Not open for further replies.

Dr. Demento

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
From what I've seen, past versions of Outlook did not have the capability of programatically signing/encrypting email; is this still the case for Outlook 2010 (32- or 64-bit)??

If that's still the case, would it be possible to use the code found here or here and turn it on/off programatically?? If so, I'm hoping that would have the same outcome as my original intent. Or, did I misunderstand the purpose of this code?

Thanks so much.
 

Dr. Demento

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Alternatively, would the code found here allow me turn on/off encryption for specified emails?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Alternatively, would the code found here allow me turn on/off encryption for specified emails?
FWIW, either this macro (which is the 'msdn one') or this itemsend macro can handle enabling it only for specific messages - the msdn macro can be assigned a button or called by another macro or you can use an if statement in the item send, such as:
if left(lcase(item.subject), 6) = "secure" then
' encrypt
end if
 

Dr. Demento

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
The MSDN macro is throwing error 438 (I think I read something about ActiveInspector not working in Office 2010??).

Alternatively, using the ItemSend macro is throwing error 424 - Object required

Everything goes off without a hitch until "SignAndEncrypt (objMail)" Can you assist? What am I doing wrong?

I'm using Office 2010; this code is reading values in a spreadsheet and calling Outlook. I have the Outlook 14.0 Object Library reference checked.

Code:
Dim objOutlook As New Outlook.Application  ' Early binding || https:msdn.microsoft.com/en-us/library/ff458119(v=office.11).aspx#odc_office_UseExcelObjectModeltoSendMail_MailingWorkbookasEmailAttachment
Dim objMail As Outlook.MailIte

For Each rngEntry In rngSPPM
    If IsFile(rngEntry.Offset(5, 0).Value & rngEntry.Offset(4, 0).Value) = True Then
      Set objMail = objOutlook.CreateItem(olMailItem)  ' Early binding
  '    Set objMail = objOutlook.CreateItem(0)  ' Late binding
      With objMail
        .DeferredDeliveryTime = SendAt  ' http:www.experiglot.com/2013/09/25/sending-delayed-emails-in-outlook-using-excel/
        .BodyFormat = olFormatPlain  ' http:www.vbaexpress.com/forum/archive/index.php/t-38578.html
        .To = rngEntry.Value
        .CC = carbon1.Value
        .Subject = rngEntry.Offset(1, 0).Value
        .Body = rngEntry.Offset(2, 0).Value & vbNewLine & vbNewLine & Signature
        .Attachments.Add rngEntry.Offset(5, 0).Value & _
                         rngEntry.Offset(4, 0).Value
        .Display ' .Send or .Save  ' ~~ Other Outlook actions for emails
      End With
      If mod_Exists.ExactWordInString(objMail.Subject, "Reconciliation") = True Then SignAndEncrypt (objMail)
    Else
      On Error Resume Next
    End If
  Next rngEntry
Thanks so much for your help!!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sorry it took so long to get to this, everytime I'd think "i need to put this in my VM and check it', I'd get side tracked. :(

Does it stop on any line? Comment out error checking lines if necessary.

> Dim objMail As Outlook.MailIte
you're missing the M in item.
 

Dr. Demento

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Diane,

No worries - I'm just grateful for the help. The missing M is a copy/paste error; it's there in 'real-life' ;-)

I've altered the code a bit; I call it using

Code:
If mod_Exists.ExactWordInString(objMail.Subject, "Reconciliation") = True _
  Then Call Sign_Encrypt(objMail)
where
Code:
Set objMail = objOutlook.CreateItem(olMailItem)
and get the error (#287) when defining oProp (=0)

Code:
Private Sub Sign_Encrypt(ByVal item As Object, Optional Cancel As Boolean)
' ~~ How to sign or encrypt a message programmatically from OOM
' https://support.microsoft.com/en-us/kb/2636465

  Dim ulFlags As Object
  Dim oProp As Long

  Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
  oProp = CLng(item.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))  '<~~~ Error 287 - application or object defined error
  ulFlags = 0
  ulFlags = ulFlags Or &H1 ' Add the encrypted flag
  ulFlags = ulFlags Or &H2 ' Add the signed flag
  item.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags

  Set item = Nothing

End Sub
BTW, the call statement and Sign_Encrypt are in the same module in Excel (Excel/Outlook 2010).
 

Dr. Demento

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Just curious if anyone had any insights as to my issues (see avatar) or my Outlook problem ;-)
 

Dr. Demento

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
No worries; just curious if anyone else could offer some insights. You can't solve ALL the world's Outlook problems; gotta leave some for other folks! :D
 
Status
Not open for further replies.
Top