【问题标题】:Retrieving the Sender’s email address from Outlook 365从 Outlook 365 检索发件人的电子邮件地址
【发布时间】:2020-10-02 03:44:00
【问题描述】:

从 W7 上的 Office 2010 升级到 W10 上的 Office 365 后,以下代码停止工作。

Option Explicit

Sub test()

    Dim OL As Outlook.Application
    Dim ST As Outlook.Store
    Dim DSI As Outlook.Folder
    Dim Email As Outlook.MailItem

    Set OL = CreateObject("Outlook.Application")

    'Find Primary Mailbox
    For Each ST In OL.GetNamespace("MAPI").Stores
        If ST.ExchangeStoreType = olPrimaryExchangeMailbox Then
            Set DSI = ST.GetDefaultFolder(olFolderSentMail)
            Exit For
        End If
        Set ST = Nothing
    Next

    Const PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

    For Each Email In DSI.Items
        Debug.Print Email.Sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
    Next

    Set Email = Nothing
    Set DSI = Nothing
    Set ST = Nothing
    Set OL = Nothing

End Sub

它现在在此行返回 287 运行时错误“应用程序定义或对象定义错误”。

Debug.Print Email.Sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)

我的研究表明这是一个信任问题;所以我尝试在代码中添加签名,但没有奏效。

我让它工作的唯一方法是直接在 Outlook VBA 上运行,并将签名应用于代码。但我需要能够从 excel VBA 运行它。

有什么建议吗?

代码的目的是识别默认发送邮件文件夹中已使用共享邮箱发送的电子邮件,并将它们移动到单独的文件夹(代码已在上面被删减,仅显示手头的错误) .正如我所说,代码在升级之前运行良好。

【问题讨论】:

  • PropertyAccessorMailItem 的属性。它不是MailItem.Sender 的属性。删除.Sender
  • 我的实验发现MailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")MailItem.SenderEmailAddress之间没有区别。
  • 你错了 - Sender 属性返回一个具有 PropertyAccessor 属性的 AddressEntry 实例。所以,代码是正确的!
  • @TonyDallimore 每次从不同邮箱发送邮件时都会有所不同(例如,“代表”邮件发送)
  • @EugeneAstafiev。你是对的,Sender 确实有属性PropertyAccessor。我从没想过要这么感谢你提供的信息。但是,我无法使用MailItemMailItem.Sender 在我的系统上获取问题中的架构地址。你知道我在哪里可以找到MailItem.Sender 的架构列表吗?

标签: excel vba outlook office365 digital-signature


【解决方案1】:

微软似乎为 Outlook 自动化实施了安全规则。有可能的路线,你可以去:

  1. 使用 Outlook 所基于的低级代码 - 扩展 MAPI 或围绕此 API 的任何其他第三方包装器,例如 Redemption。

  2. 使用专为在 Outlook 中关闭此类安全触发器而设计的第三方组件 - Security Manager for Microsoft Outlook

  3. 设置组策略以避免此类触发器。

  4. 在系统上设置有效的防病毒软件。

【讨论】:

    【解决方案2】:

    您可以尝试通过搜索(Items.RestrictItems.Find/FindNextPidTagSenderSmtpAddress MAPI 属性(DASL 名称 http://schemas.microsoft.com/mapi/proptag/0x5D01001F)上的已发送邮件文件夹来避免安全提示。

    此外,没有理由循环访问商店 - Application.Session.GetDefaultFolder() 无论如何都会为您提供默认商店中的文件夹。

    【讨论】:

    • 很好的答案。但无法使其与过滤器中的“@”字符一起使用?不得不做'ci_startswith'name@''。是否有任何转义字符可用于在过滤器中包含“@”?
    • 这对我有用... MailItem.Items.Restrict("@SQL=""schemas.microsoft.com/mapi/proptag/0x0065001E"" = 'name@domain.com'") 有没有更简单的方法来找到这些DASL 名称??我花了无数次谷歌搜索才发现这个!?
    • 当然,您可以在 OutlookSpy (dimastr.com/outspy) 中看到它们 - 点击 IMessage 按钮,选择您需要的属性,查看 DASL 编辑框。
    • 微软自己不会在任何地方列出它们吗?让新软件在我这里获得批准太费力了。
    • OutlookSpy 安装程序不需要管理员权限即可安装。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多