Based on the question and answer from @EC99 here and the comments from @DmitryStreblechenko I came up with 3 approaches to create outlook-emails from excel-vba - I think the original question pointed to the creation of outlook-emails from excel-vba. The answer from @EC99 includes outlook-vba code. Thank you both @EC99 and @DmitryStreblechenko: Without your question/answer/comments I could not do that.
What's important to know is that my answer and @EC99's answer copy the confidential label from another email.
Below you will find 3 approaches:
I. You found your values for SensitivityLabelGUID and SiteGUID and you just write it in your code (See answer from EC99 to find the values (values need to come from an confidential mail))
II. You want to use another email on your filesystem that has the confidential label to copy it from there
III. You want to use another email from outlook by its EntryID that has the confidential label to copy it from there
'Option 1 (You found your values for SensitivityLabelGUID and SiteGUID and you just write it in your code
Sub SendMail_Option1()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Dim SensitivityLabelGUID As String
Dim SiteGUID As String
Dim PropAccessor As Variant
Set PropAccessor = OutMail.PropertyAccessor
SensitivityLabelGUID = "345xy691-4219-45fd-985f-fdc3a990e22c" ' <----------- Fill your values here
SiteGUID = "1ad0323a-54x2-49a6-9e49-52tz0a954c89" ' <----------- Fill your values here
MSIPLabel = "MSIP_Label_" & SensitivityLabelGUID & "_Enabled=true;" & _
"MSIP_Label_" & SensitivityLabelGUID & "_Method=Privileged;" & _
"MSIP_Label_" & SensitivityLabelGUID & "_Name=" & SensitivityLabelGUID & ";" & _
"MSIP_Label_" & SensitivityLabelGUID & "_SetDate=" & dateTimeNow & "; " & _
"MSIP_Label_" & SensitivityLabelGUID & "_SiteId=" & SiteGUID & "; "
PropAccessor.SetProperty "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels", MSIPLabel
On Error GoTo ErrorHandler
With OutMail
.To = "[email protected]"
.CC = "[email protected]"
'.BCC = "[email protected]"
.Subject = "Test"
.HTMLBody = "Test"
.Sensitivity = 3 '2=Private 3=Confidential
.Display '.Send
End With
Exit Sub
ErrorHandler:
End Sub
'Option 2 (You want to use another email on your filesystem that has the confidential label to copy it from there)
Sub SendMail_Option2()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Dim MailTemplatePath As String
Dim MailTemplate As Object
Dim MailTemplatePropertyAccessor As String
Dim SensitivityLabelGUID As String
Dim SiteGUID As String
Dim PropAccessor As Variant
Set PropAccessor = OutMail.PropertyAccessor
MailTemplatePath = "C:\Confidential_Email_As_Sample.msg" '<----------- Fill your value here
Set MailTemplate = OutApp.CreateItemFromTemplate(MailTemplatePath)
MailTemplatePropertyAccessor = MailTemplate.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F")
SensitivityLabelGUID = Mid(MailTemplatePropertyAccessor, InStr(MailTemplatePropertyAccessor, "MSIP_Label_") + Len("MSIP_Label_"), 36)
SiteGUID = Mid(MailTemplatePropertyAccessor, InStr(MailTemplatePropertyAccessor, "SiteId=") + Len("SiteId="), 36)
MSIPLabel = "MSIP_Label_" & SensitivityLabelGUID & "_Enabled=true;" & _
"MSIP_Label_" & SensitivityLabelGUID & "_Method=Privileged;" & _
"MSIP_Label_" & SensitivityLabelGUID & "_Name=" & SensitivityLabelGUID & ";" & _
"MSIP_Label_" & SensitivityLabelGUID & "_SetDate=" & dateTimeNow & "; " & _
"MSIP_Label_" & SensitivityLabelGUID & "_SiteId=" & SiteGUID & "; "
PropAccessor.SetProperty "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels", MSIPLabel
On Error GoTo ErrorHandler
With OutMail
.To = "[email protected]"
.CC = "[email protected]"
'.BCC = "[email protected]"
.Subject = "Test"
.HTMLBody = "Test"
.Sensitivity = 3 '2=Private 3=Confidential
.Display '.Send
End With
Exit Sub
ErrorHandler:
End Sub
'Option 3 (You want to use another email from outlook by its EntryID that has the confidential label to copy it from there)
Sub SendMail_Option3()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Dim OutSession As Object
Set OutSession = OutApp.Session
Set OutMail = OutApp.CreateItem(0)
Dim MailTemplateEntryID As String
Dim MailTemplatePropertyAccessor As String
Dim SensitivityLabelGUID As String
Dim SiteGUID As String
Dim PropAccessor As Variant
Set PropAccessor = OutMail.PropertyAccessor
MailTemplateEntryID = "0000000055A868E9D99D704E94D6609666E5366B78002211D0E2E0384A41B06DC02781D89DF10012004F9X6F00009DAC56FE5596124D92023CA476945FD40001231EF4F01230" '<----------- Fill your value here
Set MailTemplate = OutSession.GetItemFromID(MailTemplateEntryID) 'Get the email item by EntryID
MailTemplatePropertyAccessor = MailTemplate.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F")
SensitivityLabelGUID = Mid(MailTemplatePropertyAccessor, InStr(MailTemplatePropertyAccessor, "MSIP_Label_") + Len("MSIP_Label_"), 36)
SiteGUID = Mid(MailTemplatePropertyAccessor, InStr(MailTemplatePropertyAccessor, "SiteId=") + Len("SiteId="), 36)
MSIPLabel = "MSIP_Label_" & SensitivityLabelGUID & "_Enabled=true;" & _
"MSIP_Label_" & SensitivityLabelGUID & "_Method=Privileged;" & _
"MSIP_Label_" & SensitivityLabelGUID & "_Name=" & SensitivityLabelGUID & ";" & _
"MSIP_Label_" & SensitivityLabelGUID & "_SetDate=" & dateTimeNow & "; " & _
"MSIP_Label_" & SensitivityLabelGUID & "_SiteId=" & SiteGUID & "; "
PropAccessor.SetProperty "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels", MSIPLabel
On Error GoTo ErrorHandler
With OutMail
.To = "[email protected]"
.CC = "[email protected]"
'.BCC = "[email protected]"
.Subject = "Test"
.HTMLBody = "Test"
.Sensitivity = 3 '2=Private 3=Confidential
.Display '.Send
End With
Exit Sub
ErrorHandler:
End Sub