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
54 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 14

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 14

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
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: …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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