0

I am having an problem I can't figure out using Classic ASP to set an appointment using an Exchange EWS post via SOAP.

The code works about 50% of the time; it depends on the exchange user that I am trying to set the appointment for.

Using the exact code below, I specify some users & the appointment is created perfectly. When I specify others users it just returns 401 unauthorized errors.

I don't have access to the Exchange Server so I can't check the user setups myself but I am being told their is no difference. One of our python developers was able to get it to work using NTLM authentication. I don't know how to implement that into the code below, nor can I find any examples.

TARGETURL="https://mail.foo.com/ews/exchange.asmx"
USERNAME="testuser1@foo.com"
PASSWORD="abc123"


reqStr = ""
reqStr = reqStr & "<?xml version='1.0' encoding='utf-8'?>"
reqStr = reqStr & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" 
reqStr = reqStr & "       xmlns:m='http://schemas.microsoft.com/exchange/services/2006/messages'"
reqStr = reqStr & "       xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'"
reqStr = reqStr & "       xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
reqStr = reqStr & "  <soap:Header>"
reqStr = reqStr & "    <t:RequestServerVersion Version='Exchange2007_SP1' />"
reqStr = reqStr & "    <t:TimeZoneContext>"
reqStr = reqStr & "      <t:TimeZoneDefinition Id='Eastern Standard Time' />"
reqStr = reqStr & "    </t:TimeZoneContext>"
reqStr = reqStr & "  </soap:Header>"
reqStr = reqStr & "  <soap:Body>"
reqStr = reqStr & "    <m:CreateItem SendMeetingInvitations='SendToNone'>"
reqStr = reqStr & "      <m:Items>"
reqStr = reqStr & "        <t:CalendarItem>"
reqStr = reqStr & "          <t:Subject>ABC Company Appointment</t:Subject>"
reqStr = reqStr & "          <t:Body BodyType='HTML'>Speak to discuss pricing</t:Body>"
reqStr = reqStr & "          <t:Start>2017-04-05T15:20:00.000Z</t:Start>"
reqStr = reqStr & "          <t:End>2017-04-05T16:20:00.000Z</t:End>"
reqStr = reqStr & "          <t:Location>Conference Room 1</t:Location>"
reqStr = reqStr & "          <t:MeetingTimeZone TimeZoneName='Eastern Standard Time' />"
reqStr = reqStr & "        </t:CalendarItem>"
reqStr = reqStr & "      </m:Items>"
reqStr = reqStr & "    </m:CreateItem>"
reqStr = reqStr & "  </soap:Body>"
reqStr = reqStr & "</soap:Envelope>"                        

'Perform the actual post
set oXMLHTTP=CreateObject("MSXML2.XMLHTTP")
set oXML=CreateObject("MSXML2.DOMDocument")


' Send the request
oXMLHTTP.Open "POST", TARGETURL, false, USERNAME, PASSWORD
oXMLHTTP.SetRequestHeader "Content-Type", "text/xml"
oXMLHTTP.Send reqStr 
user692942
  • 16,398
  • 7
  • 76
  • 175
RJS
  • 1
  • 4
    Possible duplicate of [HTTP Authentication (Basic or Digest) in ASP Classic via IIS](http://stackoverflow.com/questions/208063/http-authentication-basic-or-digest-in-asp-classic-via-iis) – user692942 Apr 10 '17 at 13:58
  • Possible duplicate of [Providing authentication info via msxml2.ServerXMLHTTP](//stackoverflow.com/q/20712635) – user692942 Apr 10 '17 at 14:57
  • I looked through both of those posts, thanks for the info. It didn't help me solve it though. To be honest I am not 100% sure the problem is rooted in NTLM, that's just my best guess. I have tried credentials for 8 user so far, 5 work, 3 don't. But I can log into outlook via the web using the credentials that don;t work for the EWS post. Very frustrating. – RJS Apr 10 '17 at 19:01
  • Take a look at [this](http://stackoverflow.com/a/13517513/692942), ignore the code as that is `c#` but the advice is the same. Depending on how the AD is setup you might need to use `DOMAIN\user` rather than `user@domain`. – user692942 Apr 11 '17 at 09:18
  • 1
    Yes, thank you. That turned out to be the solution. Using user@domain works in about 50% of the cases. Using DOMAIN\user woks in 100% of the cases. I can't say I understand why, but it's working great now and that was what I needed. – RJS Apr 12 '17 at 12:39
  • I think it's because not all the AD accounts will have the email address associated as the UPN of their account whereas they will always have the legacy equivalent *(`sAMAccountName`)*. So, it's likely more an AD management issue than a code problem. – user692942 Apr 12 '17 at 13:14
  • 1
    @RJS: You should add it as an answer to your question and mark it as the solution as a help for future readers with the same problem. – Jakob Christensen May 09 '17 at 12:39

0 Answers0