Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2007, 01:15 AM   PM User | #1
Basscyst
Smokes a Lot


 
Join Date: Jul 2003
Location: CA, USA
Posts: 1,594
Thanks: 5
Thanked 20 Times in 20 Posts
Basscyst is on a distinguished road
webDAV Downloading Attachments from Exchange Server

I have the following code, that retrieves the emails from a designated inbox, stores the message and subject content in a SQL database and then deletes them from the exchange server. This all works great.

Now I need to take the attachments for each email and save them on a different server.

I've researched this all day, and I keep finding references stating that I can download the file using, X-MS-ENUMATTS. I'm using it currently to retrieve a list of attached files, however I fail to see how I can download the attachment to my webserver using this.

The red code below is a request to the actual file. So I know the http path to the file, how do I go about saving it to my server?

Code:
<%
response.buffer="false"
%>
<!--#include file="includes/asp/db.inc"-->
<%
Set oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.3.0")
oXMLHTTP.Open "PROPFIND", "http://192.168.0.246/exchange/ts/inbox", False,"user","password"
oXMLHTTP.SetRequestHeader "Content-Type", "xml"
oXMLHTTP.SetRequestHeader "Depth", "1"
oXMLHTTP.Send
set xmlstr=oXMLHTTP.ResponseXML
set doc=xmlstr.documentElement
set mails=doc.getElementsByTagName("a:response")
For i=0 To mails.Length-1
	set Mail_Subject=mails(i).getElementsByTagName("d:subject")
	If Mail_Subject.Length <> 0 Then
		set Mail_body=mails(i).getElementsByTagName("e:textdescription")
		set Sender=mails(i).getElementsByTagName("e:fromemail")
		set o_file=mails(i).getElementsByTagName("a:href")
		ExecSQL("INSERT INTO TechMails (Mail_Subject,Mail_body,Sender) VALUES('" & Replace(Mail_Subject(0).firstChild.nodeValue,"'","''") & "','" & Replace(mail_body(0).firstChild.nodeValue,"'","''") & "','" & sender(0).firstChild.nodeValue & "')")
		
		Set oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.3.0")
		oXMLHTTP.Open "X-MS-ENUMATTS", o_file(0).firstChild.nodeValue, False,"user","password"
		oXMLHTTP.SetRequestHeader "Content-Type", "xml"
		oXMLHTTP.SetRequestHeader "Depth", "1"
		oXMLHTTP.Send
		set xmlstr=oXMLHTTP.ResponseXML
		set doc=xmlstr.documentElement
		set atts=doc.getElementsByTagName("a:response")
		attlist=""
		For j=0 To atts.Length-1
			fpath=atts(j).getElementsByTagName("a:href")(0).firstChild.nodeValue
			fname=atts(j).getElementsByTagName("e:attachmentfilename")(0).firstChild.nodeValue
			ftype=atts(j).getElementsByTagName("a:prop")(0).getElementsByTagName("d:x3703001f")(0).firstChild.nodeValue

			Set oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.4.0")
			oXMLHTTP.Open "GET",fpath, False,"user","password"
			oXMLHTTP.Send
			xmlstr=oXMLHTTP.responseText
		Next		
		Set oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.4.0")
		oXMLHTTP.Open "DELETE",o_file(0).firstChild.nodeValue,False,"user","password"
		oXMLHTTP.SetRequestHeader "Depth", "infinity"
		oXMLHTTP.Send
		set oXMLHTTP=nothing
	End If
Next
%>
<techmails>
<%
	set rs=getSQL("SELECT * FROM techMails")
	Do Until rs.EOF
%>
	<email>
		<mailsender value="<%=rs.Fields("Sender")%>" />
		<mailsubject><![CDATA[<%=rs.Fields("mail_subject")%>]]></mailsubject>
		<mailbody><![CDATA[<%=rs.Fields("mail_body")%>]]></mailbody>
	</email>
<%
	rs.MoveNext
	Loop
%>
</techmails>
Thanks,
Basscyst
__________________
Helping to build a bigger box. - Adam Matthews

Last edited by Basscyst; 05-03-2007 at 01:27 AM..
Basscyst is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 PM.


Advertisement
Log in to turn off these ads.