Howto: WebDAV X-MS-ENUMATTS using VBScript to enumerate attachments
' This example shows how to enumerate attachments on a message. X-MS-ENUMATTS will
' return phantom urls to attachments on the message. These URLs can be used with GET
' and DELETE (starting with Exchange 2003 SP1).
' For listing and reading an attachment, you will first need to get a list of attachments
' using X-MS_ENUMATTS. After getting the list of attachments you will need to parse out
' then the URL from the returned information, you can then do a GET to read the attachments.
First get a list of attachments…
Function GetAttachmentsListXML(ByVal sHREF As String, ByVal sUserName As String, ByVal sPassword As String) As String
Dim HttpWebRequest As MSXML2.XMLHTTP30
Dim strPropReq As String
Dim strOutPutFile As String
Set HttpWebRequest = New MSXML2.XMLHTTP30
With HttpWebRequest
.Open "X-MS-ENUMATTS", sHREF, False, sUserName, sPassword
.setRequestHeader "Content-type:", "text/xml"
.setRequestHeader "Depth", "1,noroot"
.Send
GetAttachmentsListXML = HttpWebRequest.ResponseText
End With
Set HttpWebRequest = Nothing
End Function
Now read the attachment…
Private Function ReadAnAttatchment(ByVal sHREF As String, ByVal sUserName As String, ByVal sPassword As String) As Variant
Dim HttpWebRequest As MSXML2.XMLHTTP30
Dim vReturn As Variant
Set HttpWebRequest = New MSXML2.XMLHTTP30
HttpWebRequest.Open "GET", sHREF, False, sUserName, sPassword
HttpWebRequest.Send
ReadAnAttatchment = HttpWebRequest.ResponseText ' Returns as text
'ReadAnAttatchment = HttpWebRequest.responseBody ' Returns as encoded
Set HttpWebRequest = Nothing
End Function
Comments
Anonymous
December 03, 2008
Hi Dan, 2 questions for you. Is there a way to get ALL the mailboxes back or do you have to use a search criteria after the CMD= and Is there a way to get back raw XML data from this request rather than the HTML that seems to be being returned to my VB.NET call to this page? many thanks and great site by the way, has been a ton of help to me the last week. AndyAnonymous
December 03, 2008
The OWA command "galfind" is what is supported to get back at least a partial list of mailboxes. However, there is no direct way for WebDAV. I don't think there is another OWA command for this - if there is it would be use at your own risk since galfind is the only thing supported in that area. Getting a list of mailboxes with WebDAV http://blogs.msdn.com/webdav_101/archive/2008/06/11/getting-a-list-of-mailboxes.aspx If your getting back HTML from a webdav call, be sure that you have the "translate" header set to "f" when making the WebDAV call. This header is normally needed for WebDAV GET and PUT calls. However doing a GET for an OWA Command is different - dont set the translate header in this case. Please keep in mind that OWA calls are not WebDAV calls. OWA is a product that you can leverage some functionality from by calling it using a GET. WebDAV is an API which provides specific sets of functionality.Anonymous
July 31, 2009
Dan, using the sample code above is it possible to 'download' the attachment. for example, if the attachment was a .pdf. Could I use GET on the attachments URL and copy the pdf to my hard drive? Thanks, Shelly