Solved

VBA code to set Sensitvity Tag to Private based on a certain recipient in the recipient lines in Outlook

Posted on 2016-10-20
4
45 Views
Last Modified: 2016-10-30
I am trying to figure out if there is a way when one of my users creates an email to a certain email group, say Friends, that the new email message will automatically set the Sensitivity Tag to Private and display a message that it was set and not allow it to be changed?  Or another possible approach would be that when the user tries to send the email with that group in one of the recipient lines it will check to see if Sensitivity Tag is set to Private and if not, it would pop up a message telling them to set it and not let the user send the email until that tag is set.  The message would continuously pop up when the user tries to send until the tag is set.

I would imagine this can be done, but I haven't coded VBA in a long time and never for Outlook.
0
Comment
Question by:TPBPIT
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Alexei Kuznetsov earned 500 total points
ID: 41853541
That's pretty easy. Something like this:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Sensitivity <> olPrivate Then
        For Each Recip In Item.Recipients
            If Recip.Address = "friends@domain.com" Then
                MsgBox "Not Private!"
                Cancel = True
                Exit For
            End If
        Next
    End If
End Sub

Open in new window

If you want, you can check Recip.Name instead of address. You may also want to set Item.Sensitivity to olPrivate automatically instead of Cancelling the message.
1
 

Author Comment

by:TPBPIT
ID: 41853983
Is there a way to OR the recip.address to allow for a couple of recipients to be check?  Say I wanted to look for Friends and Enemies.

And if you do Recip.Name instead, and you wanted to use group names from the global address list, who would you enter the name?  Just as it reads in the GAL?
0
 
LVL 13

Expert Comment

by:Alexei Kuznetsov
ID: 41854003
Yes, sure. Like this in line 4:
If Recip.Name = "Friends" Or Recip.Name = "Enemies" Then

Open in new window

0
 

Author Closing Comment

by:TPBPIT
ID: 41866030
Thanks for the help with this.  It worked perfectly.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
Read this checklist to learn more about the 15 things you should never include in an email signature.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now