leederbyshire.com  Mobile web applications for Microsoft Exchange Server.
HOME OWA FOR PDA BUY ONLINE DOWNLOADS TESTIMONIALS SCREENSHOTS FAQ UPGRADE ARTICLES CONTACT BLOG

EWS FindItem List Inbox Exchange 2007

LISTING YOUR INBOX CONTENTS WITH EWS FINDITEM

Back to Articles page

Here's a short article describing how you can use the Exchange Web Services (EWS) FindItem operation to list the ten most recent messages in your Inbox. This code was developed on Exchange 2007, but will no doubt also function with Exchange 2010 when it appears.

I'm not going to go into too much detail, but it is a demonstration of how you can use the FindItem operation to return a list of messages. The output is then displayed using XSL. Copy the code into an .htm file, and then open it in Internet Explorer. Change the http to https if necessary (probably not), supply the name of your Exchange server, and click the button. It may ask you to login.

Hopefully, you will be rewarded with a list of the most recent message in your Inbox. Not too exciting, admittedly, but a nice demonstration (I hope) of the power and ease-of-use of the EWS access method.

<html>
<head>
<script language="VBScript">

Dim objXMLHTTP, objXMLDoc

Sub getMessages_OnClick()
  strProtocol = document.all.protocol.value
  strServerName = document.all.server.value
  strURL = strProtocol & "://" & strServername & "/EWS/Exchange.asmx"
  Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
  objXMLHTTP.Open "POST", strURL, True
  objXMLHTTP.setRequestHeader "Content-type:", "text/xml"
  objXMLHTTP.onReadyStateChange = getRef("checkXMLHTTPState")
  strXML = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
   "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""" & _
   " xmlns:m=""http://schemas.microsoft.com/exchange/services/2006/messages""" & _
   " xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">" & _
   "<soap:Body>" & _
   "<m:FindItem Traversal=""Shallow"">" & _
   "<m:ItemShape>" & _
   "<t:BaseShape>Default</t:BaseShape>" & _
   "</m:ItemShape>" & _
   "<m:IndexedPageItemView MaxEntriesReturned=""10"" BasePoint=""Beginning"" Offset=""0""/>" & _
   "<m:ParentFolderIds>" & _
   "<t:DistinguishedFolderId Id=""inbox""/>" & _
   "</m:ParentFolderIds>" & _
   "</m:FindItem>" & _
   "</soap:Body>" & _
   "</soap:Envelope>"
  objXMLHTTP.Send(strXML)
End Sub

Sub checkXMLHTTPState
  If objXMLHTTP.readyState = 4 Then
    responseStatus.innerHTML = objXMLHTTP.Status & " - " & objXMLHTTP.StatusText
    Set objXMLDoc = objXMLHTTP.ResponseXML
    XSLDiv.innerHTML = objXMLDoc.TransformNode(responseXSL.documentElement)
    Set objXMLHTTP = Nothing
    Set objXMLDoc = Nothing
  End If
End Sub

</script>
<xml id="responseXSL">
<xsl:template xmlns:xsl="uri:xsl" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <xsl:for-each select="//t:Message">
    <xsl:value-of select="t:Subject"/><br/>
  </xsl:for-each>
</xsl:template>
</xml>

</head>
<body>
<font face="Sans-serif" size="2">
<input name="protocol" value="http" size="5">://<input name="server">
<input type="button" name="getMessages" value="GO">
<span id="responseStatus"></span>
<p>
<div id="XSLDiv"></div>
</body>
</html>

Exchange Shared Folder For Windows Phone
Copyright © 2014 Lee Derbyshire. All rights reserved.