Getting a list of mailboxes with WebDAV


OK, WebDAV does not have the ability itself to get a list of mailboxes.  However you can use other APIs and even use an OWA call to get a list of mailboxes.


 


Reading the GAL:


 


WebDAV itself cannot do this.  You could use the OWA GALFIND command, which has some limited ability.  You could also use ADSI, CDO 1.21 or Extended MAPI as long as you’re running in-network.  There is no Exchange Web Service (EWS) call for doing this (at least not in Exchange 2007 SP1)).


 


GALFIND:


 


GALFIND is an OWA call which is supported to use.  It is not a WebDAV call.  Basically, you do a GET against a URL and pass it search parameters.


 


Format of the OWA call:


 


sServerURL = “http://”+ sServerURL + “/public/?Cmd=galfind


 


Information on the unsupported call is covered in the following article:


Customizing Microsoft Outlook Web Access


http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=6532E454-073E-4974-A800-1490A7CB358F  


 


Basic call – use the following URI and choose “GET – OWA Call” – you will not need a body, all info past to OWA are in the uri:


 


http://<Exchange server>/exchange/?cmd=galfind


 


Here are the possible search Parameters:


 


      DN        Display Name                ex: Robert Jones


      FN        First Name                     ex: Robert


      LN         Last Name                    ex: Jones


      TL         Title                              ex: Big Manager


      AN        Alias                             ex: bobj


      CP        Company                      ex: microsoft   


      DP        Department                    ex: Exchange


      OF        Office                            ex: Bld 15/2124


      CY        City                               ex: Redmond


 


Note: There is no ability to search against other fields such as phone number, etc.


 


Example URIs:


http://myexserver/public/?Cmd=galfind&an=bobj


http://myexserver/exchange/administrator/Inbox/?cmd=galfind&an=a


http://myexserver/exchange/administrator/Inbox/?cmd=galfind&cp=microsoft


 


Example Raw Request:


 


GET – OWA Call http://myexchangeserver/exchange/myuser/?cmd=galfind HTTP/1.1


Pragma: no-cache


Content-Type: text/xml


User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)


 


Here are the supported methods:


 


CDO 1.21:


How To Work with Distribution Lists Using CDO (1.x) from Visual Basic


http://support.microsoft.com/?id=178787 


 


ADSI:


241474 HOWTO: Render the Global Address List with ADSI


http://support.microsoft.com/?id=241474 


 


Extended MAPI:


166106 HOWTO: Getting the Contents of the Exchange Global Address List


http://support.microsoft.com/?id=166106 


 


More on using Extended MAPI to read the Mailbox Table:


 


The Mailbox Table in Exchange holds a list of Mailboxes and related mailbox information.  Reading this table can only be done with Extended MAPI or WMI can be used on an Exchange 2003 server.   


 


Extended MAPI can be used with Exchange 5.5 and later.


 


XCLN: How to Retrieve Last Logon Time of Exchange Users Using Extended MAPI


http://support.microsoft.com/default.aspx?scid=kb;en-us;259570  


 


How to loop through mailboxes on Exchange by using the GetMailboxTable method


http://support.microsoft.com/kb/200160/


 


With Exchange 2003 and later, you can use WMI:


 


LastLogonTime Property


http://msdn.microsoft.com/en-us/library/aa144762.aspx 


 


Here is a sample of using GALFIND:


 


‘  GALFIND Sample


‘ GALFIND will return results which can be consumed by your application as xml.


‘ You can test the URL by putting it into IE and seeing the results.


‘  TODO: Have Basic Authentication turned ON on the virtual directory for the item and no anonymous.


‘  Note: there is no Translate header set for a GET against an OWA URL – That’s because we are not using WebDAV, we are using the results from an OWA page.


 


sub ReadFileText (sFile)


    Dim objFSO ‘As FileSystemObject


    dim oTS


    dim sText


   


    Set objFSO = CreateObject(“Scripting.FileSystemObject”)


 


    Set oTS = objFSO.OpenTextFile(sFile)


    sText = oTS.ReadAll


 


    oTS.close


    set oTS = nothing


    Set objFSO = nothing


 


    ReadFileText = sText


    


end sub


 


Private Sub WriteFileText(sFilePath, sText)


    Dim objFSO ‘As FileSystemObject


    Dim objTextFile ‘As Object


   


    Const ForReading = 1


    Const ForWriting = 2


    Const ForAppending = 8


   


    Set objFSO = CreateObject(“Scripting.FileSystemObject”)


    Set objTextFile = objFSO.CreateTextFile(sFilePath, True)


   


    ‘ Write a line.


    objTextFile.Write (sText)


 


    objTextFile.Close


    ‘objTextFile.Close


 


End Sub


 


 


dim sHREF


dim sUserName 


dim sPassword 


dim sResponse 


Dim HttpWebRequest


 


shref=”http://myexchangeserver.company.com/exchange/?cmd=galfind&DN=bobbie” mce_href=”http://myexchangeserver.company.com/exchange/?cmd=galfind&DN=bobbie”  ‘ TODO: change


 


sUserName = “Administrator”    ‘ TODO: change


sPassword = “”    ‘ TODO: change


 


set HttpWebRequest = CreateObject(“microsoft.xmlhttp”)


 


if sPassword = “” then


    HttpWebRequest.Open “GET”, sHREF , False


else


    HttpWebRequest.Open “GET”, sHREF , False,  sUserName, sPassword


end if


 


HttpWebRequest.Send


sResponse  = HttpWebRequest.ResponseText  ‘ Returns as text


 


Set HttpWebRequest = Nothing


wscript.echo sResponse 


 


 

Comments (11)

  1. danba says:

    Under Exchange 2007, you can also use PowerShell to get the Global Address List – call Get-GlobalAddress List.  Exchange 2010 allows you to do remote calls using Remote PowerShell.  

    Please refer to the following:

       http://technet.microsoft.com/en-us/library/bb123703(EXCHG.80).aspx

  2. danba says:

    If your code .NET based, you should look at using the System.DirectoryServices namespace.  This allows you to search against AD to get the Global Address List.

  3. fnando521@gmail.com says:

    I'm trying to execute this using Jquery $.ajax command. It's working but I'm having trouble getting the XML data parsed and I think it's because there is <html> tags included with the response back from the exchange server url. Does anyone know how to get the raw xml back cleanly? I appreciate any assistance.

  4. danba says:

    Hello fnando521@gmail.com;

    Getting back an html tag back in the response is usually due to missing headers in the GET request. Are you using all of the headers?  … such as the Content-Type…?

    GET – OWA Call http://myexchangeserver/exchange/myuser/?cmd=galfind HTTP/1.1

    Pragma: no-cache

    Content-Type: text/xml

    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)

    Which version of Exchange are you going against?

  5. fnando521@gmail.com says:

    Thanks for the quick reply. We migrated to Exchange 2007-but i think we might still have a 2003 server.  I'm not using all the headers you mentioned. Let me try that and I'll post my results.

  6. fnando521@gmail.com says:

    I tried adding all the headers but it's still returning html in the response. Do you happen to have an example of this using JQuery, rather than asp/vb ? I'm attempting to build a mobile app that can access this data so it would need to run client side.

  7. danba says:

    I don't have any JQuery examples.  Are you using the "exchange" virtual directory or "owa"?  It should be "exchange" – the same as it was for 2003.  Have  you tried the VBScript sample above to see if you get the same response?

  8. fnando521 says:

    I'll try your vb sample and see if I get the same results. The url I use is https://exchangeserver/public/?cmd=galfind&fn=bob

    It returns the correct data in the browser but also includes <html>.

  9. Hey fnando521 – I ran into the same exact thing.  Try adding some UserAgent settings stuff in your code.  You can hit it that way with JQuery, dude.  Good luck with that one and let me know how it works out.  Peace.

  10. Fnando521 says:

    Yeah I needed to add the correct 'User-Agent' in the request header, and now I'm able to get the data correctly! Thanks!