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