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
J VBA Cannot programmatically input or change Value for User Defined field Using Outlook 1
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
Rupert Dragwater How to permanently remove an email address Using Outlook 9
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
F Auto changing email subject line in bulk Using Outlook 2
F Want to add second email to Outlook for business use Using Outlook 3
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Shift Delete doesn't delete email from server Using Outlook 4
K Incorporate selection from combobox into body of email Outlook VBA and Custom Forms 0
L Why are some email automatically going to "archive" Using Outlook 2
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 1
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0
Rupert Dragwater Duplicate email in Folder Using Outlook 8
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 0
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0

Similar threads

Top