【问题标题】:How to get email address from the emails inside an Oulook folder via PowerShell?如何通过 PowerShell 从 Outlook 文件夹中的电子邮件中获取电子邮件地址?
【发布时间】:2017-11-13 21:25:27
【问题描述】:

我有一个 Outlook 文件夹,我们称之为 LoremIpsum,其中有超过 1000 份电子邮件草稿,我想列举并通过 PowerShell 进行一些过滤。我可以使用此脚本访问该文件夹并查看电子邮件:

Function HandleRemaining {
    [CmdletBinding()]
    Param()

    BEGIN {
        Clear-Host
    }

    PROCESS {
        $outlook = New-Object -ComObject outlook.application
        $mapi = $outlook.getnamespace("MAPI");

        $email = $mapi.Folders.Item(1).Folders.Item('LoremIpsum').Items(1)

        foreach ($recip in $email.Recipients) {
           $recip 
        }

        $email.To
        $email.CC
    }

    END {
    }
}

HandleRemaining

问题是$recip$email.To 都没有返回该电子邮件的ToCC 的电子邮件地址,而是我得到了该人的解析名称,例如:

Application           : Microsoft.Office.Interop.Outlook.ApplicationClass
Class                 : 4
Session               : Microsoft.Office.Interop.Outlook.NameSpaceClass
Parent                : System.__ComObject
Address               : /o=ExchangeLabs/ou=Exchange Administrative Group (ALPHA-NUMERIC)/cn=Recipients/cn=LONG-ALPHANUMERIC-HERE
AddressEntry          : System.__ComObject
AutoResponse          : 
DisplayType           : 0
EntryID               : <snip>
Index                 : 1
MeetingResponseStatus : 0
Name                  : John Walker
Resolved              : True
TrackingStatus        : 0
TrackingStatusTime    : 01-Jan-01 00:00:00
Type                  : 1
PropertyAccessor      : System.__ComObject
Sendable              : True

John Walker

我更改了数字和代码以保护隐私,但这就是我得到的回报。 那么,我如何才能获得给定电子邮件草稿的收件人的正确电子邮件地址?

【问题讨论】:

    标签: powershell email outlook mapi


    【解决方案1】:

    我认为您需要使用 PropertyAccessor。

    $PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    $smtpAddress = $recip.PropertyAccessor.GetProperty($PR_SMTP_ADDRESS)
    

    请看这里(警告!VBA):https://msdn.microsoft.com/en-us/VBA/Outlook-VBA/articles/obtain-the-e-mail-address-of-a-recipient

    【讨论】:

    • 天哪**。我恨你微软,看看这些阴暗的东西,确实是这样。非常感谢老兄!你应该编辑你的帖子在PR_SMTP_ADDRESS之前添加$
    • 将来是否应该对其他人有所帮助,更多属性/模式在这里:stackoverflow.com/a/45296809/361842
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2013-09-07
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多