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.
Similar threads
Thread starter Title Forum Replies Date
B Programmatically force html send and insert clipboard contents into body Outlook VBA and Custom Forms 0
oliv- Reduce the size of picture attachments: programmatically Outlook VBA and Custom Forms 3
B Adding controls programmatically Using Outlook 1
M programmatically make all Appointmentitem olResource Attendees unsendable Using Outlook 1
S Programmatically accessing Outlook Calendar data Using Outlook 1
R Send appointments data to a Form programmatically Outlook VBA and Custom Forms 2
M How to connect to SQL DB from outlook programmatically? Outlook VBA and Custom Forms 1
B Programmatically scheduling WebEx meetings through Outlook Outlook VBA and Custom Forms 1
N Help in programmatically setting formatting in an AppointmentItem Outlook VBA and Custom Forms 3
K Programmatically accessing Outlook properties Outlook VBA and Custom Forms 3
V How to programmatically set "Display reminders and tasks frm pstfolder Outlook VBA and Custom Forms 1
R Displaying a field from the field chooser programmatically Outlook VBA and Custom Forms 1
M How to programmatically select a outlook search folder? Outlook VBA and Custom Forms 1
M How to install custom mapi form programmatically? Outlook VBA and Custom Forms 1
A Programmatically duplicating BCM's "Link to Record" function BCM (Business Contact Manager) 2
B Accessing Outlook 2003 Signature Programmatically using C# Outlook VBA and Custom Forms 6
L Programmatically moving between pages in a form Outlook VBA and Custom Forms 2
S Programmatically bring up Advanced Find for contacts? Outlook VBA and Custom Forms 1
S assign task programmatically Outlook VBA and Custom Forms 2
S do Reply, Reply to All, Forward programmatically Outlook VBA and Custom Forms 2
U unable to encrypt email Using Outlook 9
R State of encrypt and sign button for a saved mail?(draft) Outlook VBA and Custom Forms 3
R About state of encrypt and sign button for outlook? Outlook VBA and Custom Forms 7
R Encrypt and sign button while word is editor for outlook? Outlook VBA and Custom Forms 6
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
S Macro to extract email addresses of recipients in current drafted email and put into clipboard Outlook VBA and Custom Forms 2
A Is there an ID field you can use to pair a reply to the sent email? Outlook VBA and Custom Forms 4
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
A Prepending Email Addrs with "Display Name <email>" Has Stopped Working Using Outlook 0
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
W Reply to email Using Outlook 4
F Junk Email does not get added to the Blocked Sender List Using Outlook 4
B disappearing original when attach to email Using Outlook 1
W September 2020 - No Default Email Client message after Office Update Using Outlook 1
glnz O365 - How to combine the Inboxes for four email accounts into a single Inbox Using Outlook 7
glnz O365 - How to send from acct 2 but showing email name from acct 1 as From - alias? Using Outlook 0
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
E Asking user to select multiple options in a list in an email Outlook VBA and Custom Forms 0
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
B Add ComboBox Value to Body of Email Outlook VBA and Custom Forms 1
A Backup Email Accounts On OutLook For Mac 2016 (Microsoft 365 subscription version) Using Outlook 0
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
G Inbox shows old email Using Outlook 3
L Email with correct To address but displaying name of a related person Using Outlook 0
A Two Inboxes, Same Email? Using Outlook 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1

Similar threads

Top