none
Connect Office365 Mailbox using EWS API RRS feed

  • Question

  • Hi Together

    I have following Problem.

    I am trying to connect to a Mailbox in office365 Cloud but getting error message that the Server is unreachable.

    Could someone can send me the right way how to do it and is it possible.

    I am using following powershell Code.

    Function ConnectExchangeService() { [Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll") | Out-Null $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1) $service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials('username@domain.com','password') $service.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx"); $service.traceenabled = "true" return $service }

    $service = ConnectExchangeService

    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxToConnect)     $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)


    Bind is giving me following Error and i dont know what am i doing wrong.

    Exception calling "Bind" with "2" argument(s): "The request failed. The remote server returned an error: (503) Server Unavailable."

    Could someone help me please or give me right documentation specific for EWS API and Office 365.

    Thanks in advance for your help.



    • Edited by todomati Thursday, March 30, 2017 8:52 AM
    Thursday, March 30, 2017 8:50 AM

Answers

  • Hi Together

    The Problem is solved.

    The EWS URL was wrong and Service user account had also a Problem.

    This was caused by moving from on-premise Exchange to Exchange online.

    This Function with this URL and user account is working(it must be upn from Service account user) for Exchange Online ews connection

    Function ConnectExchangeService()
    {
    [Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll") | Out-Null
    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
    $service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials('username@domain.com','password')
    $service.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx");
    $service.traceenabled = "true"
    return $service
    }

    • Marked as answer by todomati Friday, March 31, 2017 3:16 PM
    Friday, March 31, 2017 3:16 PM

All replies

  • Hi, 

    Someone already asked this question: https://social.msdn.microsoft.com/Forums/exchange/en-US/a5b90082-90d1-487c-9139-d776c3af20a8/ews-bind-error-message?forum=exchangesvrdevelopment

    Hope this helps!


    Regards, Sjoukje

    Please remember to click 'Mark as Answer' on the post that helps you.

    Thursday, March 30, 2017 1:01 PM
    Moderator
  • Hi Sjoukje

    Thanks for your answer but your solution concern normal on-permise Exchange connect...

    My Problem is that the Mailboxes and Exchange are in Cloud...and using office365...

    Any other suggestions?

    Friday, March 31, 2017 7:10 AM
  • One thing more.

    I am not so familiar with Exchange in Cloud enviroment.

    Is this URL the right one for connecting Cloud Mailbox...

    https://outlook.office365.com/EWS/Exchange.asmx

    Cheers


    • Edited by todomati Friday, March 31, 2017 7:14 AM
    Friday, March 31, 2017 7:12 AM
  • Hi Together

    The Problem is solved.

    The EWS URL was wrong and Service user account had also a Problem.

    This was caused by moving from on-premise Exchange to Exchange online.

    This Function with this URL and user account is working(it must be upn from Service account user) for Exchange Online ews connection

    Function ConnectExchangeService()
    {
    [Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll") | Out-Null
    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
    $service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials('username@domain.com','password')
    $service.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx");
    $service.traceenabled = "true"
    return $service
    }

    • Marked as answer by todomati Friday, March 31, 2017 3:16 PM
    Friday, March 31, 2017 3:16 PM
  • Hi,

    Great to hear that your problem is solved! Thanks for sharing!


    Regards, Sjoukje

    Please remember to click 'Mark as Answer' on the post that helps you.

    Saturday, April 1, 2017 9:38 AM
    Moderator