【问题标题】:Is it possible to extract recipient email address from a .msg file? [duplicate]是否可以从 .msg 文件中提取收件人电子邮件地址? [复制]
【发布时间】:2018-04-07 02:07:39
【问题描述】:

为了从一批 .msg 文件中编译收件人列表,我正在尝试使用 powershell 来实现这一点。我可以获取收件人姓名,但不能获取他们的电子邮件。他们的地址条目显示为 System._ComObject

对我做错了什么以及如何解决这个问题有什么建议吗?谢谢。

$outlook = New-Object -ComObject Outlook.Application
$namespace = $outlook.GetNameSpace("MAPI")

Get-ChildItem $msgPath -Filter *.msg |
    ForEach-Object{
        $msg = $outlook.Session.OpenSharedItem($_.FullName)
        $recipient = $msg.Recipients
        $address = $recipient.Address
        $recipient
        }
    $outlook.quit()

【问题讨论】:

  • 编辑后,我可以访问该属性,但没有任何输出。 @TheMuffinMan
  • 我建议获取 Outlook Spy 并检查特定邮件以查看 SMTP 地址的位置。不幸的是,电子邮件并不总是在地址中,也不总是电子邮件地址。有时它是一个交换邮箱字符串,有时它位于一些不起眼的 MAPI 属性中。对于专门为 EMAIL 构建的应用程序,您会认为访问电子邮件地址是最直接的操作。
  • @TheMuffinMan 如果我只吐出 $recipient 我会收到一个交换邮箱字符串。有没有办法解决那个字符串?也许通过活动目录搜索?

标签: powershell outlook powershell-4.0


【解决方案1】:

感谢 Palle Due:https://stackoverflow.com/a/47264921/361842

$outlook = New-Object -ComObject Outlook.Application
$namespace = $outlook.GetNameSpace("MAPI")

Get-ChildItem $msgPath -Filter *.msg |
    ForEach-Object{
        $msg = $outlook.Session.OpenSharedItem($_.FullName)
        $msg.Recipients | ForEach-Object{
            $_.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")
        }
    }
$outlook.quit()

关于特殊属性值;这里有一个有用的列表:https://stackoverflow.com/a/45296809/361842

【讨论】:

  • (投票关闭,因为链接的答案为您提供了您所追求的;但我已将 Palle 的解决方案包含在您的代码中以同时提供帮助)
  • 这太棒了!太感谢了。 @JohnLBevan
猜你喜欢
  • 1970-01-01
  • 2019-01-09
  • 1970-01-01
  • 2016-04-12
  • 1970-01-01
  • 2019-01-03
  • 2015-12-28
  • 2012-09-20
  • 1970-01-01
相关资源
最近更新 更多