Share via


HOWTO: EWS: Consume Exchange Web Service from VBScript

Yes you can consume Exchange Web Service using VBScript or any language / platform which support HTML.

In this sample, I have used XMLHTTP to send/receive soap request/response. Then I have used MSXML Document to parse the XML returned by the server to get the response code.

I have converted my recently posted sample, HOWTO: EWS: Disable Out-of-office / OOF message to VBScript code.

Const strUrl = "https://Your-Cas-Server/ews/exchange.asmx"

Const strUser = "Username"

Const strPass = "Password"

Const strDom = "Domain"

Const strEmailAddress = "youremail@domain.com"

Dim oXml

Dim xmlDoc

Dim strXmlData

Set oXml = CreateObject("MSXML2.XMLHTTP")

Set xmlDoc = CreateObject("MSXML2.DOMDocument")

strXmlData = "<?xml version=""1.0"" encoding=""utf-8""?>"

strXmlData = strXmlData & "<soap:Envelope xmlns:soap=""https://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""https://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""https://www.w3.org/2001/XMLSchema"">"

strXmlData = strXmlData & " <soap:Body>"

strXmlData = strXmlData & " <SetUserOofSettingsRequest xmlns=""https://schemas.microsoft.com/exchange/services/2006/messages"">"

strXmlData = strXmlData & " <Mailbox xmlns=""https://schemas.microsoft.com/exchange/services/2006/types"">"

strXmlData = strXmlData & " <Address>" & strEmailAddress & "</Address>"

strXmlData = strXmlData & " </Mailbox>"

strXmlData = strXmlData & " <UserOofSettings xmlns=""https://schemas.microsoft.com/exchange/services/2006/types"">"

strXmlData = strXmlData & " <OofState>Disabled</OofState>"

strXmlData = strXmlData & " <ExternalAudience>All</ExternalAudience>"

strXmlData = strXmlData & " <InternalReply>"

strXmlData = strXmlData & " <Message />"

strXmlData = strXmlData & " </InternalReply>"

strXmlData = strXmlData & " <ExternalReply>"

strXmlData = strXmlData & " <Message />"

strXmlData = strXmlData & " </ExternalReply>"

strXmlData = strXmlData & " </UserOofSettings>"

strXmlData = strXmlData & " </SetUserOofSettingsRequest>"

strXmlData = strXmlData & " </soap:Body>"

strXmlData = strXmlData & "</soap:Envelope>"

oXml.open "POST", strUrl, False, strDom & "\" & strUser, strPass

oXml.setRequestHeader "Content-Type", "text/xml"

oXml.send strXmlData

If oXml.Status = "200" Then

If xmlDoc.loadXML(oXml.responseText) Then

If xmlDoc.documentElement.getElementsByTagName("ResponseMessage").Item(0).Attributes.getNamedItem("ResponseClass").Text = "Success" Then

MsgBox "Oof Disabled"

Else

MsgBox "Oof Cannot be disabled" & vbCrLf & xmlDoc.xml

End If

End If

Else

MsgBox "Error: " & oXml.Status & " - " & oXml.statusText

End If

Keywords: VBScript, MSXML, XMLHTTP, SetUserOofSettings, ExchangeImpersonation, Exchange Web Services, Exchange 2007, Out Of Office

Comments

  • Anonymous
    November 21, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/11/22/howto-ews-consume-exchange-web-service-from-vbscript/

  • Anonymous
    January 14, 2008
    The comment has been removed

  • Anonymous
    January 16, 2008
    Yes you can read the text file and pass it between <Message>This is A Multiline Body</Message>

  • Anonymous
    October 13, 2008
    Would it be possible to just read if the OOF is set and read out the message. Yours is one of the few examples of using VBScript in this way that I have been able o find, but I need to adapt this to just read the setting... do you have an example using VBScript to just read out properties or settings? I plan to us one authenticated user to read the OOF settings for all users...

  • Anonymous
    October 15, 2008
    At this point of time you cannot use EWS to set OOF message for other than yourself. This feature should be available in next SP release of Exchange 2007. Till that time you need to stay with MAPI being the only way to Set/Read OOF message for others.

  • Anonymous
    February 24, 2009
    I had explained earlier how you can consume Exchange Web Services like WebDAV from VBScript in the below

  • Anonymous
    July 23, 2010
    For some strange reason, this script, when run from the server, gives "401 - Unauthorized" but when run from a remote workstation, works just fine for my user and for others. I have the strDom set to the mydomain.local form but have also tried just mydomain. The strURL value has to be set to www.mydomain.com/.../exchange.asmx (note the https rather than http as shown) or I get 403 - Forbidden both inside and out. Any idea how to get this working inside? Then I can move on to how to change the soap to read messages from a users mailbox. Small change, I'm sure. LOL...