如何通过 PowerShell 从 Oulook 文件夹内的电子邮件中获取电子邮件地址? [英] How to get email address from the emails inside an Oulook folder via PowerShell?

查看:43
本文介绍了如何通过 PowerShell 从 Oulook 文件夹内的电子邮件中获取电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Outlook 文件夹,我们称之为 LoremIpsum,我有 1000 多个电子邮件草稿要枚举并通过 PowerShell 进行一些过滤.我可以使用此脚本访问该文件夹并查看电子邮件:

I have an Outlook folder, let's call it LoremIpsum, where I have more than 1000+ email drafts that I want to enumarate and do some filtering via PowerShell. I can access the folder and see the emails already, using this script:

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,而是我得到了该人的解析名称,例如:

The problem is that neither $recip nor $email.To return the email address of the To or CC of that email, instead I get the person's resolved name, example:

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

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

I changed the numbers and codes to preserve privacy, but that's the return I get. So, how can I get the proper emaill address of the recipients of a given email draft?

推荐答案

我认为您需要使用 PropertyAccessor.

I think you need to use the 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

See here (Warning! VBA): https://msdn.microsoft.com/en-us/VBA/Outlook-VBA/articles/obtain-the-e-mail-address-of-a-recipient

这篇关于如何通过 PowerShell 从 Oulook 文件夹内的电子邮件中获取电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆