azure 使用VBA更改Outlook 365电子邮件中的SensitivityLabel

jchrr9hc  于 2023-08-07  发布在  其他
关注(0)|答案(2)|浏览(252)

如何访问Outlook 365中的Office.SensitivityLabel方法来为新电子邮件创建和设置标签?
查看您将使用的文档

Dim myLabelInfo As Office.LabelInfo
Set myLabelInfo = ActiveDocument.SensitivityLabel.CreateLabelInfo()

字符串
创建标签对象,但Outlook邮件项或Outlook应用程序中没有ActiveDocument对象。
Office.SensitivityLabel成员的对象浏览器视图


的数据

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail
    .To = myRecipients
    .Subject = mySubject
    .BodyFormat = olFormatHTML
    .HTMLBody = myEmailBody
    '' Set Office.SensitivityLabel  // how do I set the label ?
    .Send
End With

ijxebb2r

ijxebb2r1#

我发现的唯一方法是使用SendKeys,如果标签列表发生变化,这很容易出现问题。

Set Mail_Object = Outlook_App.CreateItem(olMailItem)

With Mail_Object
    
    '
    ' Set the Sensitivity Label - until details on how to access the property directly come to light
    '
    .Display
    
    SendKeys "%h" ' Alt H - gets the home menu
    SendKeys "AY" ' Sensitivity Label
    SendKeys "{DOWN}{DOWN}{ENTER}" ' Change the number of {DOWN} to select a particular value from your list
    
    .Send ' Send it
    
End With

字符串

j1dl9f46

j1dl9f462#

我找到了一些代码来标记文档,但不知道如何将其适应VBA以将标签设置为Mail对象。
https://www.codeproject.com/Tips/5324059/Azure-Information-Protection-AIP-Labelling-in-VBsc
我已经得到了我需要的属性,根据这个:https://learn.microsoft.com/en-us/office/vba/api/overview/library-reference/labelinfo-members-office
这是我正在使用的代码,不知道如何完成它。

Sub EnviarCorreo(ByVal correo As String, ByVal titulo As String, ByVal body As String, ByVal fichero As String)
On Error Resume Next ' Capturar errores durante el envío del correo

Dim olApp As Object
Set olApp = CreateObject("Outlook.Application") ' Crear una instancia de Outlook

If Not olApp Is Nothing Then ' Verificar si se obtuvo una instancia válida de Outlook
    Dim olMail As Object
    Set olMail = olApp.CreateItem(0) ' 0 indica el tipo de item MailItem
    With olMail
        .To = correo
        .Subject = titulo
        .body = body
        .Attachments.Add (fichero)
    .Send
    End With
Else
    MsgBox "No se pudo obtener una instancia válida de Outlook.", vbExclamation
End If

Set olMail = Nothing
Set olApp = Nothing

字符串
结束子

相关问题