We help IT Professionals succeed at work.

Problem accessing EWS from Linux application server

Low Priority
Last Modified: 2018-06-11
Good day,
I have Exchange 2010. I have Sugar CRM on Linux system that needs to access my EWS.
The code in the Sugar CRM system is:
// Request
            $xmlstr = <<<XML
                        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
                SendMeetingInvitations="SendToAllAndSaveCopy" >
        <t:DistinguishedFolderId Id="calendar"/>
        <t:CalendarItem xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
          <Subject>Planning Meeting</Subject>
          <Body BodyType="Text">Plan the agenda for next week's meeting.</Body>
          <Location>Conference Room 721</Location>
            $serviceURL = 'https://myServer.Mydomain/ews/exchange.asmx';
            $username = 'domainname\username';
            $password = 'Password';
            $ch = curl_init($serviceURL);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
            curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8' , 'Expect:'));
            curl_setopt($ch, CURLOPT_POST, false);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET" ); // *this resolves the 405 http code return*
            curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlstr);
            $GLOBALS['log']->fatal("before.." );
            $response = curl_exec($ch);  
            $GLOBALS['log']->fatal("response = " . print_r($response,true) );

We get 401 error with the following responce

Thu May 24 16:04:45 2018 [11448][1][FATAL] response = HTTP/1.1 401 Unauthorized ( The server requires authorization to fulfill the request. Access to the Web server is denied. Contact the server administrator.  )
WWW-Authenticate: Basic Realm="MyServer.Mydomian"
Connection: Keep-Alive
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 2057  

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML dir=ltr><HEAD><TITLE>The page cannot be displayed</TITLE>
<STYLE id=L_defaultr_1>A:link {
            FONT: 8pt/11pt verdana; COLOR: #ff0000
A:visited {
            FONT: 8pt/11pt verdana; COLOR: #4e4e4e

<META content=NOINDEX name=ROBOTS>
<META http-equiv=Content-Type content="text-html; charset=UTF-8">

<META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<TABLE cellSpacing=5 cellPadding=3 width=410>
    <TD vAlign=center align=left width=360>
      <H1 id=L_defaultr_2 style="FONT: 13pt/15pt verdana; COLOR: #000000"><ID id=L_defaultr_3><!--Problem-->The page cannot be displayed
    <TD width=400 colSpan=2><FONT id=L_defaultr_4
      style="FONT: 8pt/11pt verdana; COLOR: #000000"><ID id=L_defaultr_5><B>Explanation: </B>There is a problem with the page you are trying to reach and it cannot be displayed.</ID></FONT></TD></TR>
    <TD width=400 colSpan=2><FONT id=L_defaultr_6
      style="FONT: 8pt/11pt verdana; COLOR: #000000">
      <HR color=#c0c0c0 noShade>

      <P id=L_defaultr_7><B>Try the following:</B></P>
        <LI id=L_defaultr_8><B>Refresh page:</B> Search for the page again by clicking the Refresh button. The timeout may have occurred due to Internet congestion.
<LI id=L_defaultr_9><B>Check spelling:</B> Check that you typed the Web page address correctly. The address may have been mistyped.
<LI id=L_defaultr_10><B>Access from a link:</B> If there is a link to the page you are looking for, try accessing the page from that link.

      <HR color=#c0c0c0 noShade>

      <P id=L_defaultr_11>Technical Information (for support personnel)</P>
        <LI id=L_defaultr_12>Error Code: 401 Unauthorized. The server requires authorization to fulfill the request. Access to the Web server is denied. Contact the server administrator. (12209)


Microsoft's connection tester works for bioth EWS tests.
In the EWS and IIS logs I don't see the request from the Sugar CRM (which makes me woder who is answering the 401 error...)
The EWS is behind an ISA server.
Watch Question

Israel SilbergInfrastructure manager


In order to make things more clear,
I see other users go through the EWS from phones and mail clients (mainly Outlook), only when we try to connect from this Linux machine he gets 401 error. Same user with the Microsoft tester is working.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.