Aurelien
Aurelien

Reputation: 728

Accessing Inbox and SentItems folder on EWS using powershell

I'm struggling with some EWS via PowerShell code. It seems I can't access both the Sent Items and the Inbox folders at the same time.

Here's my code:

$ewsPath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
Add-Type -Path $ewsPath
$ews = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList "Exchange2013"
$ews.Credentials = New-Object Net.NetworkCredential('emailbox', 'password')
$ews.AutodiscoverUrl("[email protected]")
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$sentbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SentItems)
$iv = New-object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 10000                                         
$pvSet = New-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)                                               
$sentItems = $sentbox.FindItems($iv)

When I want to get the Sent Items folder in the sentbox variable I get the following error:

Exception when calling "Bind" with "2" argument (s): "The request failed. The remote server returned an error: (501) Not implemented.

But if I had the following line between the $inbox and $sentbox initialization it works, but the findItems on $sentbox fails.

$ews.AutodiscoverUrl("[email protected]")

Upvotes: 0

Views: 1679

Answers (1)

Aurelien
Aurelien

Reputation: 728

It was an issue about firewalls. The code works.

Upvotes: 0

Related Questions