'How to apply AIP labels to an Outlook email using VBA?
I have a VBA function in our MS Access database that generates Outlook emails and sends them from a shared inbox. Our company uses Azure Information Protection in order to protect documents. A label needs to be applied to each email before it is sent out (eg. Public, Business Sensitive, Internal).
Rather than having the end user click the label 25 times as it pops up for each email, I was trying to apply it programmatically. I thought the answer was as simple as I tried below, but I am getting a strange error code (-1248837627) from VB.
My solution to do this was to grab the labels GUID and then apply it to the email as below... I have come across other solutions such as using SendKeys but I simply do not like that approach and would prefer it to be a last resort.
With olMail
.To = olSendTo
.Subject = olSubject
.PermissionTemplateGuid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX"
.Permission = olPermissionTemplate
'And so on, the email function works great until the above two lines are added
Am I applying the .Permissions or .PermissionTemplateGUID improperly? There is such little information available on this any help at all is appreciated. I have seen a similar approach work to applying labels to excel documents (grabbing and setting the guid).
Solution 1:[1]
The code you posted is used to specify Information Rights Management (IRM) permissions. Azure Information Protection is another story.
You need to add a user property in the following format:
"MSIP_Label_" & guid_internal_use_only & "_Enabled"
But I'd suggest exploring internals of Outlook mail items using MFCMAPI or OutlookSpy to find the exact solution. Try to set it manually then explore internals using these tools.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugene Astafiev |
