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 = "https://"+ sServerURL + "/public/?Cmd=galfind
Information on the unsupported call is covered in the following article:
Customizing Microsoft Outlook Web Access
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:
https://<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:
https://myexserver/public/?Cmd=galfind&an=bobj
https://myexserver/exchange/administrator/Inbox/?cmd=galfind&an=a
https://myexserver/exchange/administrator/Inbox/?cmd=galfind&cp=microsoft
Example Raw Request:
GET - OWA Call https://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
https://support.microsoft.com/?id=178787
ADSI:
241474 HOWTO: Render the Global Address List with ADSI
https://support.microsoft.com/?id=241474
Extended MAPI:
166106 HOWTO: Getting the Contents of the Exchange Global Address List
https://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
https://support.microsoft.com/default.aspx?scid=kb;en-us;259570
How to loop through mailboxes on Exchange by using the GetMailboxTable method
https://support.microsoft.com/kb/200160/
With Exchange 2003 and later, you can use WMI:
LastLogonTime Property
https://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="https://myexchangeserver.company.com/exchange/?cmd=galfind&DN=bobbie" mce_href="https://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
Anonymous
June 14, 2008
PingBack from http://www.basketballs-sports.info/basketball-chat/?p=1674Anonymous
December 10, 2009
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).aspxAnonymous
December 10, 2009
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.Anonymous
April 22, 2011
The comment has been removedAnonymous
April 22, 2011
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?Anonymous
April 22, 2011
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.Anonymous
April 22, 2011
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.Anonymous
April 22, 2011
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?Anonymous
April 22, 2011
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>.Anonymous
April 28, 2011
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.Anonymous
April 28, 2011
Yeah I needed to add the correct 'User-Agent' in the request header, and now I'm able to get the data correctly! Thanks!