Exchange Web服务使用PowerShell读取电子邮件正文

时间:2016-03-11 04:42:20

标签: powershell exchangewebservices exchange-server-2010

我试图阅读发送到帐户的电子邮件。 这些电子邮件是我们团队需要采取行动的通知。 现在我们进去,阅读新的电子邮件,复制并粘贴所需的信息,删除电子邮件,等待新的电子邮件进入。

我一直在使用EWS获取一些信息,但我需要帮助...... 1)将正文检索为文本而不是html 2)将找到的电子邮件移动到已删除的文件夹。         明确宿主

## Define UPN of the Account that has impersonation rights
$AccountWithImpersonationRights = "admin@mycorp.com"

##Define the SMTP Address of the mailbox to impersonate
$MailboxToImpersonate = "user@mycorp.com"

## Load Exchange web services DLL
## Download here if not present: http://go.microsoft.com/fwlink/?LinkId=255472
$dllpath = "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll"
Import-Module $dllpath

## Set Exchange Version
$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2

## Create Exchange Service Object
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)

#Get valid Credentials using UPN for the ID that is used to impersonate mailbox
$Service.UseDefaultCredentials = $true 

## Set the URL of the CAS (Client Access Server)
$uri=[system.URI] "https://webmail.mycorp.com/ews/exchange.asmx" 
$service.url = $uri

#$service.AutodiscoverUrl($AccountWithImpersonationRights ,{$true})
##Login to Mailbox with Impersonation
Write-Host 'Using ' $AccountWithImpersonationRights ' to Impersonate ' $MailboxToImpersonate
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SMTPAddress,$MailboxToImpersonate );

#Connect to the Inbox and display basic statistics
$InboxFolder= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$ImpersonatedMailboxName)
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$InboxFolder)

Write-Host 'Total Item count for Inbox:' $Inbox.TotalCount
Write-Host 'Total Items Unread:' $Inbox.UnreadCount
Write-Host ""

Write-Host "Scanning remote mailbox: " -ForegroundColor Yellow -NoNewline ; Write-Host $MailboxToImpersonate
Write-Host ""
$mailitems = $null
$mailitems = $inbox.FindItems(2000)

$mailitems | ForEach {$_.Load()}

`

0 个答案:

没有答案