【问题标题】:Encrypt Outlook Mail Programmatically via VBA通过 VBA 以编程方式加密 Outlook 邮件
【发布时间】:2017-06-15 09:32:59
【问题描述】:

我正在寻找一种在 Outlook 2013 中通过 VBA 代码加密和发送 Outlook 邮件的方法。

我希望我可以访问邮件对象并调用类似“加密”的方法。

Microsoft 表示,“Microsoft Outlook 对象模型不提供直接支持以编程方式对邮件消息进行签名或加密”,但可以为其构建解决方案。 (https://support.microsoft.com/de-de/help/2636465/how-to-sign-or-encrypt-mail-messages-programmatically)

我知道我可以手动加密邮件,但我想以编程方式访问它。也许我可以像设置此属性时调用的事件或调用的东西一样调用。

我没有任何证书。有没有办法在不使用证书的情况下在 Outlook 中加密邮件?

【问题讨论】:

  • 您可以查看 Outlook Redemption Library,iirc 它提供了一些超出标准对象模型的加密技术。
  • @RyanWildry 遗憾的是,这并没有提供以编程方式执行此操作的方法,就像我说我知道有选项但 Outlook 不接受我的个人 ssl 证书,无论出于何种原因。

标签: vba email encryption outlook


【解决方案1】:

【讨论】:

  • 这是目前为止的工作,但还需要证书才能工作。没有证书也可以吗?
【解决方案2】:

这个信息出奇地难找。如果上述链接失效,这里有一个实现设置 PR_SECURITY_FLAGS 属性的函数。

'---------------------------------------------------------------------------------------
' Procedure : Mailitem_SignEncr
' Date      : 2019-06-11
' Author    : Andre 
' Purpose   : Set security flags for an Outlook Mailitem
'
' Source: https://blogs.msdn.microsoft.com/dvespa/2009/03/16/how-to-sign-or-encrypt-a-message-programmatically-from-oom/
' Parameters:
' oItem: If your code runs in Outlook VBA, you can use this to get the current mail: Set oItem = Application.ActiveInspector.CurrentItem
'        Otherwise you get this object when creating the new mail item.
' doSign: Digital Signature. +1 = ON, -1 = OFF, 0 = leave default
' doEncr: Encryption.        +1 = ON, -1 = OFF, 0 = leave default
'---------------------------------------------------------------------------------------
'
Public Sub Mailitem_SignEncr(oItem As Outlook.MailItem, doSign As Long, doEncr As Long)

    Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
    Const SECFLAG_ENCRYPTED As Long = &H1
    Const SECFLAG_SIGNED As Long = &H2

    Dim SecFlags As Long

    ' Get current flags value
    SecFlags = oItem.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS)

    ' Turn flags on/off

    If doSign > 0 Then
        ' ON
        SecFlags = SecFlags Or SECFLAG_SIGNED
    ElseIf doSign < 0 Then
        ' OFF
        SecFlags = SecFlags And (Not SECFLAG_SIGNED)
    Else
        ' leave this flag as it is
    End If

    If doEncr > 0 Then
        SecFlags = SecFlags Or SECFLAG_ENCRYPTED
    ElseIf doEncr < 0 Then
        SecFlags = SecFlags And (Not SECFLAG_ENCRYPTED)
    End If

    ' and set the modified flags
    oItem.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, SecFlags

End Sub

【讨论】:

  • 太棒了!令人难以置信的是,它还没有 API。这就像黑魔法! :-\
猜你喜欢
  • 1970-01-01
  • 2018-09-03
  • 1970-01-01
  • 2010-12-30
  • 1970-01-01
  • 1970-01-01
  • 2022-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多