Encrypting an email VBA code

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hello, good afternoon, i am hoping you can help me please? I have the code below which works great :), but i now need to encrypt every email i send, is there anyway this can be added into my code below at all please? i am still fairly new to this and still learning, any help you offer will be greatly appreciated.
HTML:
Private Sub CommandButton1_Click()

Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String

Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)

          aEmail.HTMLBody = "<html>******>" & _
                            "<p>Hi " & Me.TextBox35.Value & "</p>" & _
                            "<p>" & Me.TextBox33.Value & "</p>" & _
                            "<p>" & Me.TextBox17.Value & "</p>" & _
                            "<table border=""1"", cellpadding=""10"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                            "<th>Date:</th>" & _
                            "<td>" & Me.TextBox18.Text & "</td><td>" & Me.TextBox19.Text & "</td>" & _
                            "<td>" & Me.TextBox21.Text & "</td><td>" & Me.TextBox23.Text & "</td>" & _
                            "<td>" & Me.TextBox25.Text & "</td><td>" & Me.TextBox26.Text & "</td>" & _
                            "</tr>" & _
                "<tr>" & _
                            "<th>Area:</th>" & _
                            "<td>" & Me.TextBox9.Value & "</td><td>" & Me.TextBox20.Value & "</td>" & _
                            "<td>" & Me.TextBox22.Value & "</td><td>" & Me.TextBox24.Value & "</td>" & _
                            "<td>" & Me.TextBox29.Value & "</td><td>" & Me.TextBox30.Value & "</td>" & _
                            "</tr>" & _
                            "</table>" & _
                "<br><br><br><br><br><br>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"


        aEmail.Recipients.Add (UserForm1.TextBox36.Value)
        aEmail.CC = (UserForm1.TextBox37.Value)
        aEmail.BCC = ""
        aEmail.Subject = "Weekly " & Range("D2").Value
        aEmail.Display
        
Unload Me

End Sub
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hello, good morning, just wondering if you guys had any ideas on how to help with my query on how to make my emails encrypted and to add the VBA into my code above at all please? thank you again for your time :)
 
Upvote 0
hi i have seen it thank you but please can you advise where i put the below code in my code?

Code:
Sub SignAndEncrypt()

    Const PR_SECURITY_FLAGS = "[URL]http://schemas.microsoft.com/mapi/proptag/0x6E010003[/URL]"

    Dim mi As MailItem

    Set mi = Application.ActiveInspector.CurrentItem

    Dim prop As Long

    prop = CLng(mi.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))

    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED

    ulFlags = ulFlags Or &H2 ' SECFLAG_SIGNED

    mi.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags

    Set mi = Nothing

End Sub
 
Upvote 0
hi all i have added the code to my prev code but i get a compile error: user defined type not defined, and it highlights in yellow
Code:
Dim mi As MailItem
, please can you help ? thank you again

HTML:
Private Sub CommandButton1_Click()

    Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"

    Dim mi As MailItem

    Set mi = Application.ActiveInspector.CurrentItem

    Dim prop As Long

    prop = CLng(mi.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))

    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED

    ulFlags = ulFlags Or &H2 ' SECFLAG_SIGNED

    mi.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags

    Set mi = Nothing
    
    End With
    
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String

Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)

          aEmail.HTMLBody = "<html>******>" & _
                            "<p>Hi " & Me.TextBox35.Value & "</p>" & _
                            "<p>" & Me.TextBox33.Value & "</p>" & _
                            "<p>" & Me.TextBox17.Value & "</p>" & _
                            "<table border=""1"", cellpadding=""10"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                            "<th>Date:</th>" & _
                            "<td>" & Me.TextBox18.Text & "</td><td>" & Me.TextBox19.Text & "</td>" & _
                            "<td>" & Me.TextBox21.Text & "</td><td>" & Me.TextBox23.Text & "</td>" & _
                            "<td>" & Me.TextBox25.Text & "</td><td>" & Me.TextBox26.Text & "</td>" & _
                            "</tr>" & _
                "<tr>" & _
                            "<th>Area:</th>" & _
                            "<td>" & Me.TextBox9.Value & "</td><td>" & Me.TextBox20.Value & "</td>" & _
                            "<td>" & Me.TextBox22.Value & "</td><td>" & Me.TextBox24.Value & "</td>" & _
                            "<td>" & Me.TextBox29.Value & "</td><td>" & Me.TextBox30.Value & "</td>" & _
                            "</tr>" & _
                            "</table>" & _
                "<br><br><br><br><br><br>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"


        aEmail.Recipients.Add (UserForm1.TextBox36.Value)
        aEmail.CC = (UserForm1.TextBox37.Value)
        aEmail.BCC = ""
        aEmail.Subject = "Weekly " & Range("D2").Value
        aEmail.Display
        
Unload Me

End Sub
 
Upvote 0
Hi sorry me again, just wondering if you had any ideas on how to help me please with the above code? i have inputted the code on the link provided into my original code but i get the compile error: user defined type not defined', i hope you can help to rectify this error? i am still new to this and still learning and your help is greatly appreciated.
 
Upvote 0
Hi Good morning, just wondering if you had any ideas with my issue at all please? i hope you can help me :)
 
Upvote 0
Hi Good morning, please can you help me with the code below, i have pasted the additional code to encrypt into my vba code i already had but i am coming up with an error, please can you help, thank you
HTML:
Private Sub CommandButton1_Click()

    Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"

    Dim mi As MailItem

    Set mi = Application.ActiveInspector.CurrentItem

    Dim prop As Long

    prop = CLng(mi.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))

    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED

    ulFlags = ulFlags Or &H2 ' SECFLAG_SIGNED

    mi.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags

    Set mi = Nothing
    
    End With
    
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String

Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)

          aEmail.HTMLBody = "<html>******>" & _
                            "<p>Hi " & Me.TextBox35.Value & "</p>" & _
                            "<p>" & Me.TextBox33.Value & "</p>" & _
                            "<p>" & Me.TextBox17.Value & "</p>" & _
                            "<table border=""1"", cellpadding=""10"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                            "<th>Date:</th>" & _
                            "<td>" & Me.TextBox18.Text & "</td><td>" & Me.TextBox19.Text & "</td>" & _
                            "<td>" & Me.TextBox21.Text & "</td><td>" & Me.TextBox23.Text & "</td>" & _
                            "<td>" & Me.TextBox25.Text & "</td><td>" & Me.TextBox26.Text & "</td>" & _
                            "</tr>" & _
                "<tr>" & _
                            "<th>Area:</th>" & _
                            "<td>" & Me.TextBox9.Value & "</td><td>" & Me.TextBox20.Value & "</td>" & _
                            "<td>" & Me.TextBox22.Value & "</td><td>" & Me.TextBox24.Value & "</td>" & _
                            "<td>" & Me.TextBox29.Value & "</td><td>" & Me.TextBox30.Value & "</td>" & _
                            "</tr>" & _
                            "</table>" & _
                "" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"


        aEmail.Recipients.Add (UserForm1.TextBox36.Value)
        aEmail.CC = (UserForm1.TextBox37.Value)
        aEmail.BCC = ""
        aEmail.Subject = "Weekly " & Range("D2").Value
        aEmail.Display
        
Unload Me

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top