 |
|
|
|
| Author |
Message |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Fri Jul 27, 2007 1:08 pm Post subject: get e-mail from Exchange Server 2003 |
|
|
looking for a way to extract e-mails from Exchange Server 2003.
save attachment, iterate through e-mail body to create txt file.
considerations:
NOT for interactive user (e.g., OOM), i.e., without having to allow
premition to mailbox.
application Cannot reside directly on mail Server.
==========================================
code so far:
Dim sUri As String
sUri = "http://Exserver.com/exchange/user/inbox/"
Dim sSubject As String = "Finsettle ERD reports Ltd"
Dim sSender As String = "ERD Export Utility"
Dim myUri As System.Uri = New System.Uri(sUri)
Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)
Dim sQuery As String
sQuery = "" & _
"" & _
"SELECT ""DAV:displayname"", " & _
"""DAV:href"" " & _
"FROM SCOPE('SHALLOW TRAVERSAL OF """ & sUri & """')" & _
"WHERE ""urn:schemas:mailheader:subject"" = '" + sSubject + "' " & _
"AND ""urn:schemas:mailheader:fromname"" = '" + sSender + "' " & _
"AND ""urn:schemas:httpmail:read"" = '0' " & _
"" & _
""
Dim myCred As NetworkCredential = New
NetworkCredential("Domain\U.name", "P@ssword")
Dim MyCredentialCache As CredentialCache = New CredentialCache()
MyCredentialCache.Add(myUri, "Basic", myCred)
HttpWRequest.Credentials = MyCredentialCache
HttpWRequest.KeepAlive = False
HttpWRequest.Headers.Set("Pragma", "no-cache")
HttpWRequest.Headers.Set("Translate", "f")
HttpWRequest.Headers.Set("Depth", "0")
HttpWRequest.ContentType = "text/xml"
HttpWRequest.ContentLength = sQuery.Length
HttpWRequest.Timeout = 300000
' set the request method. But which method?
HttpWRequest.Method = "POST" '"SEARCH" "GET" "SAVE"
==============================================
thats what i have so long..
would very much appreciate an example, directions, reference...
thanks,
j.
Archived from group: microsoft>public>exchange2000>development |
|
| Back to top |
|
 |
Glen Scales [MVP]
Joined: 05 Aug 2007 Posts: 92
|
Posted: Mon Jul 30, 2007 2:43 pm Post subject: Re: get e-mail from Exchange Server 2003 |
|
|
That is code for a Search request which will just enumerate messages in a
folder. To enumerate attachments you need to use X-MS-ENUMATTS Method. I
would suggest having a read of WebDAV 101
http://blogs.msdn.com/webdav_101/archive/2006/06/30/652851.aspx. This has
various samples of what you are trying to do as well as some good
explanations to go along with it.
Cheers
Glen
"josephine" wrote in message @microsoft.com...
> looking for a way to extract e-mails from Exchange Server 2003.
> save attachment, iterate through e-mail body to create txt file.
>
> considerations:
> NOT for interactive user (e.g., OOM), i.e., without having to allow
> premition to mailbox.
> application Cannot reside directly on mail Server.
> ==========================================
> code so far:
> Dim sUri As String
> sUri = "http://Exserver.com/exchange/user/inbox/"
> Dim sSubject As String = "Finsettle ERD reports Ltd"
> Dim sSender As String = "ERD Export Utility"
> Dim myUri As System.Uri = New System.Uri(sUri)
> Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)
>
> Dim sQuery As String
> sQuery = "" & _
> "" & _
> "SELECT ""DAV:displayname"", " & _
> """DAV:href"" " & _
> "FROM SCOPE('SHALLOW TRAVERSAL OF """ & sUri & """')" & _
> "WHERE ""urn:schemas:mailheader:subject"" = '" + sSubject + "' " &
> _
> "AND ""urn:schemas:mailheader:fromname"" = '" + sSender + "' " & _
> "AND ""urn:schemas:httpmail:read"" = '0' " & _
> "" & _
> ""
>
> Dim myCred As NetworkCredential = New
> NetworkCredential("Domain\U.name", "P@ssword")
> Dim MyCredentialCache As CredentialCache = New CredentialCache()
> MyCredentialCache.Add(myUri, "Basic", myCred)
> HttpWRequest.Credentials = MyCredentialCache
>
> HttpWRequest.KeepAlive = False
> HttpWRequest.Headers.Set("Pragma", "no-cache")
>
> HttpWRequest.Headers.Set("Translate", "f")
> HttpWRequest.Headers.Set("Depth", "0")
> HttpWRequest.ContentType = "text/xml"
> HttpWRequest.ContentLength = sQuery.Length
>
> HttpWRequest.Timeout = 300000
> ' set the request method. But which method?
> HttpWRequest.Method = "POST" '"SEARCH" "GET" "SAVE"
> ==============================================
>
> thats what i have so long..
> would very much appreciate an example, directions, reference...
>
>
> thanks,
> j. |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Mon Jul 30, 2007 2:36 am Post subject: Re: get e-mail from Exchange Server 2003 |
|
|
many thanks Glen, for the reference.
"Glen Scales [MVP]" wrote:
> That is code for a Search request which will just enumerate messages in a
> folder. To enumerate attachments you need to use X-MS-ENUMATTS Method. I
> would suggest having a read of WebDAV 101
> http://blogs.msdn.com/webdav_101/archive/2006/06/30/652851.aspx. This has
> various samples of what you are trying to do as well as some good
> explanations to go along with it.
>
> Cheers
> Glen
>
> "josephine" wrote in message
> @microsoft.com...
> > looking for a way to extract e-mails from Exchange Server 2003.
> > save attachment, iterate through e-mail body to create txt file.
> >
> > considerations:
> > NOT for interactive user (e.g., OOM), i.e., without having to allow
> > premition to mailbox.
> > application Cannot reside directly on mail Server.
> > ==========================================
> > code so far:
> > Dim sUri As String
> > sUri = "http://Exserver.com/exchange/user/inbox/"
> > Dim sSubject As String = "Finsettle ERD reports Ltd"
> > Dim sSender As String = "ERD Export Utility"
> > Dim myUri As System.Uri = New System.Uri(sUri)
> > Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)
> >
> > Dim sQuery As String
> > sQuery = "" & _
> > "" & _
> > "SELECT ""DAV:displayname"", " & _
> > """DAV:href"" " & _
> > "FROM SCOPE('SHALLOW TRAVERSAL OF """ & sUri & """')" & _
> > "WHERE ""urn:schemas:mailheader:subject"" = '" + sSubject + "' " &
> > _
> > "AND ""urn:schemas:mailheader:fromname"" = '" + sSender + "' " & _
> > "AND ""urn:schemas:httpmail:read"" = '0' " & _
> > "" & _
> > ""
> >
> > Dim myCred As NetworkCredential = New
> > NetworkCredential("Domain\U.name", "P@ssword")
> > Dim MyCredentialCache As CredentialCache = New CredentialCache()
> > MyCredentialCache.Add(myUri, "Basic", myCred)
> > HttpWRequest.Credentials = MyCredentialCache
> >
> > HttpWRequest.KeepAlive = False
> > HttpWRequest.Headers.Set("Pragma", "no-cache")
> >
> > HttpWRequest.Headers.Set("Translate", "f")
> > HttpWRequest.Headers.Set("Depth", "0")
> > HttpWRequest.ContentType = "text/xml"
> > HttpWRequest.ContentLength = sQuery.Length
> >
> > HttpWRequest.Timeout = 300000
> > ' set the request method. But which method?
> > HttpWRequest.Method = "POST" '"SEARCH" "GET" "SAVE"
> > ==============================================
> >
> > thats what i have so long..
> > would very much appreciate an example, directions, reference...
> >
> >
> > thanks,
> > j.
>
>
> |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Mon Jul 30, 2007 6:54 am Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
back here Glen.
cant seem to get actual e-mail (again..).
JOBS:
iterate through e-mail body, create txt file.
save attachment to a network folder.
code:
Dim sHREF As String
Dim sResponse As String
Dim HttpWebRequest
Dim sUserName As String = "DOMAIN\UserName"
Dim sPassword As String = "P@SSW0RD!"
Dim response As String = ""
sHREF = "http://MAILSERVER.com/exchange/UNmae/Inbox/"
Dim mItem As String = "Finsettle ERD reports.EML"
HttpWebRequest = CreateObject("microsoft.xmlhttp")
sHREF = sHREF + mItem
HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
HttpWebRequest.setRequestHeader("Translate:", "f")
HttpWebRequest.Send()
sResponse = HttpWebRequest.ResponseText
Questins PLEASE:
HOWTO get e-mail body as text from sResponse???
HOWTO get Attachment, save as txt from sResponse??? |
|
| Back to top |
|
 |
Glen Scales [MVP]
Joined: 05 Aug 2007 Posts: 92
|
Posted: Tue Jul 31, 2007 9:11 pm Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
You can get the email address of the sender from the
urn:schemas:httpmail:fromemail property
to download an attachment something like
server = "servername"
mailbox = "mailbox"
set fso = createobject("Scripting.FileSystemObject")
strURL = "http://" & server & "/exchange/" & mailbox & "/inbox/"
strURL1 = "http://" & server & "/exchange/" & mailbox & "/sent items/"
strQuery = ""
strQuery = strQuery & "SELECT ""DAV:displayname"",
""urn:schemas:httpmail:subject"""
strQuery = strQuery & " FROM scope('shallow traversal of """
strQuery = strQuery & strURL & """') Where ""DAV:ishidden"" = False AND
""DAV:isfolder"" = False AND "
strQuery = strQuery & """urn:schemas:httpmail:read"" = false AND "
strQuery = strQuery & """urn:schemas:httpmail:hasattachment"" = True
"
set req = createobject("microsoft.xmlhttp")
req.open "SEARCH", strURL, false
req.setrequestheader "Content-Type", "text/xml"
req.setRequestHeader "Translate","f"
req.send strQuery
If req.status >= 500 Then
ElseIf req.status = 207 Then
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("a:displayname")
set oNodeList1 = oResponseDoc.getElementsByTagName("a:href")
For i = 0 To (oNodeList.length -1)
set oNode = oNodeList.nextNode
set oNode1 = oNodeList1.nextNode
wscript.echo oNode.Text
embedattach(oNode1.Text)
Next
Else
End If
function embedattach(objhref)
req.open "X-MS-ENUMATTS", objhref, false, "", ""
req.send
If req.status > 207 Or req.status < 207 Then
wscript.echo "Status: " & req.status
wscript.echo "Status text: " & req.statustext
wscript.echo "Response text: " & req.responsetext
Else
wscript.echo ""
wscript.echo "Attachment"
set resDoc1 = req.responseXML
Set objPropstatNodeList1 = resDoc1.getElementsByTagName("a:propstat")
Set objHrefNodeList1 = resDoc1.getElementsByTagName("a:href")
If objPropstatNodeList1.length > 0 Then
wscript.echo objPropstatNodeList1.length & " attachments found..."
For f = 0 To (objPropstatNodeList1.length -1)
set objPropstatNode1 = objPropstatNodeList1.nextNode
set objHrefNode1 = objHrefNodeList1.nextNode
wscript.echo "Attachment: " & objHrefNode1.Text
set objNodef =
objPropstatNode1.selectSingleNode("a:prop/d:x37050003")
wscript.echo "Attachment Method: " & objNodef.Text
set objNodef2 = objPropstatNode1.selectSingleNode("a:prop/f:cn")
wscript.echo "CN: " & objNodef2.Text
if objNodef.Text = 5 then
embedattach(objHrefNode1.Text)
else
set objNode1f =
objPropstatNode1.selectSingleNode("a:prop/d:x3704001f")
wscript.echo "Attachment name: " & objNode1f.Text
req.open "GET", objHrefNode1.Text, false, "", ""
req.send
set stm = createobject("ADODB.Stream")
stm.open
msgstring = req.responsetext
stm.type = 2
stm.Charset = "x-ansi"
stm.writetext msgstring,0
stm.Position = 0
stm.type = 1
stm.savetofile "c:\temp\" & objNode1f.Text,2
set stm = nothing
end if
next
Else
wscript.echo "No file attachments found..."
End If
End If
wscript.echo
end function
Cheers
Glen
"josephine" wrote in message @microsoft.com...
> back here Glen.
> cant seem to get actual e-mail (again..).
>
> JOBS:
> iterate through e-mail body, create txt file.
> save attachment to a network folder.
>
> code:
> Dim sHREF As String
> Dim sResponse As String
> Dim HttpWebRequest
> Dim sUserName As String = "DOMAIN\UserName"
> Dim sPassword As String = "P@SSW0RD!"
> Dim response As String = ""
> sHREF = "http://MAILSERVER.com/exchange/UNmae/Inbox/"
> Dim mItem As String = "Finsettle ERD reports.EML"
> HttpWebRequest = CreateObject("microsoft.xmlhttp")
> sHREF = sHREF + mItem
> HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> HttpWebRequest.setRequestHeader("Translate:", "f")
> HttpWebRequest.Send()
> sResponse = HttpWebRequest.ResponseText
>
> Questins PLEASE:
> HOWTO get e-mail body as text from sResponse???
> HOWTO get Attachment, save as txt from sResponse??? |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Tue Jul 31, 2007 10:22 am Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
thanks again Glen for your help.
sorry, bit confused here,
as you stated my first code wasnt the right direction, and suggested the
WebDav101 as reference.
last suggested code falls on "Rec.Send StrQuery".
have also realised that sResponse will hold body of e-mail in it;
is this a good way to go on for "Create txt file from e-mail body"???
HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
HttpWebRequest.setRequestHeader("Translate:", "f")
HttpWebRequest.Send()
sResponse = HttpWebRequest.ResponseText ' Returns as text
Create_File(Date.Today, sResponse)
missing the SaveAs functionality for the attachment.
"Glen Scales [MVP]" wrote:
> You can get the email address of the sender from the
> urn:schemas:httpmail:fromemail property
>
> to download an attachment something like
>
> server = "servername"
> mailbox = "mailbox"
> set fso = createobject("Scripting.FileSystemObject")
> strURL = "http://" & server & "/exchange/" & mailbox & "/inbox/"
> strURL1 = "http://" & server & "/exchange/" & mailbox & "/sent items/"
> strQuery = ""
> strQuery = strQuery & "SELECT ""DAV:displayname"",
> ""urn:schemas:httpmail:subject"""
> strQuery = strQuery & " FROM scope('shallow traversal of """
> strQuery = strQuery & strURL & """') Where ""DAV:ishidden"" = False AND
> ""DAV:isfolder"" = False AND "
> strQuery = strQuery & """urn:schemas:httpmail:read"" = false AND "
> strQuery = strQuery & """urn:schemas:httpmail:hasattachment"" = True
> "
> set req = createobject("microsoft.xmlhttp")
> req.open "SEARCH", strURL, false
> req.setrequestheader "Content-Type", "text/xml"
> req.setRequestHeader "Translate","f"
> req.send strQuery
> If req.status >= 500 Then
> ElseIf req.status = 207 Then
> set oResponseDoc = req.responseXML
> set oNodeList = oResponseDoc.getElementsByTagName("a:displayname")
> set oNodeList1 = oResponseDoc.getElementsByTagName("a:href")
> For i = 0 To (oNodeList.length -1)
> set oNode = oNodeList.nextNode
> set oNode1 = oNodeList1.nextNode
> wscript.echo oNode.Text
> embedattach(oNode1.Text)
> Next
> Else
> End If
>
> function embedattach(objhref)
> req.open "X-MS-ENUMATTS", objhref, false, "", ""
> req.send
> If req.status > 207 Or req.status < 207 Then
> wscript.echo "Status: " & req.status
> wscript.echo "Status text: " & req.statustext
> wscript.echo "Response text: " & req.responsetext
> Else
> wscript.echo ""
> wscript.echo "Attachment"
> set resDoc1 = req.responseXML
> Set objPropstatNodeList1 = resDoc1.getElementsByTagName("a:propstat")
> Set objHrefNodeList1 = resDoc1.getElementsByTagName("a:href")
> If objPropstatNodeList1.length > 0 Then
> wscript.echo objPropstatNodeList1.length & " attachments found..."
> For f = 0 To (objPropstatNodeList1.length -1)
> set objPropstatNode1 = objPropstatNodeList1.nextNode
> set objHrefNode1 = objHrefNodeList1.nextNode
> wscript.echo "Attachment: " & objHrefNode1.Text
> set objNodef =
> objPropstatNode1.selectSingleNode("a:prop/d:x37050003")
> wscript.echo "Attachment Method: " & objNodef.Text
> set objNodef2 = objPropstatNode1.selectSingleNode("a:prop/f:cn")
> wscript.echo "CN: " & objNodef2.Text
> if objNodef.Text = 5 then
> embedattach(objHrefNode1.Text)
> else
> set objNode1f =
> objPropstatNode1.selectSingleNode("a:prop/d:x3704001f")
> wscript.echo "Attachment name: " & objNode1f.Text
> req.open "GET", objHrefNode1.Text, false, "", ""
> req.send
> set stm = createobject("ADODB.Stream")
> stm.open
> msgstring = req.responsetext
> stm.type = 2
> stm.Charset = "x-ansi"
> stm.writetext msgstring,0
> stm.Position = 0
> stm.type = 1
> stm.savetofile "c:\temp\" & objNode1f.Text,2
> set stm = nothing
> end if
> next
> Else
> wscript.echo "No file attachments found..."
> End If
> End If
> wscript.echo
> end function
>
> Cheers
> Glen
>
> "josephine" wrote in message
> @microsoft.com...
> > back here Glen.
> > cant seem to get actual e-mail (again..).
> >
> > JOBS:
> > iterate through e-mail body, create txt file.
> > save attachment to a network folder.
> >
> > code:
> > Dim sHREF As String
> > Dim sResponse As String
> > Dim HttpWebRequest
> > Dim sUserName As String = "DOMAIN\UserName"
> > Dim sPassword As String = "P@SSW0RD!"
> > Dim response As String = ""
> > sHREF = "http://MAILSERVER.com/exchange/UNmae/Inbox/"
> > Dim mItem As String = "Finsettle ERD reports.EML"
> > HttpWebRequest = CreateObject("microsoft.xmlhttp")
> > sHREF = sHREF + mItem
> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> > HttpWebRequest.setRequestHeader("Translate:", "f")
> > HttpWebRequest.Send()
> > sResponse = HttpWebRequest.ResponseText
> >
> > Questins PLEASE:
> > HOWTO get e-mail body as text from sResponse???
> > HOWTO get Attachment, save as txt from sResponse???
>
>
> |
|
| Back to top |
|
 |
Glen Scales [MVP]
Joined: 05 Aug 2007 Posts: 92
|
Posted: Wed Aug 01, 2007 2:28 pm Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
I would also suggest you have a read of the Exchange SDK as well there's is
lot more to using webdav then just having the samples. Eg you need to work
out first what authentication your using on your server to make sure your
request will succeed. If you are getting an error message what is the status
code your getting this will generally tell you what the problem is.
Using a GET request will get the entire message as a RFC 822 stream (your
attachments will be MIME encoded within the stream) you will then need to
parse that stream to make any sense of it you could do this using something
like CDOSYS. While this method works and is entirely valid it may or may not
be appropriate for what you trying to do eg if you just want to pull one
property from a message then using a Propfind on that particular property is
easier then pulling the entire message back.
If you are using .NET then I would use something like
http://msdn2.microsoft.com/en-us/library/aa563016.aspx if you combine this
with CDOSYS (or CDOEX) to parse the mail in question this is one method that
should work eg
Option Explicit On
Option Strict On
Module Module1
Sub Main()
' Variables.
Dim Request As System.Net.HttpWebRequest
Dim Response As System.Net.HttpWebResponse
Dim MyCredentialCache As System.Net.CredentialCache
Dim strPassword As String
Dim strDomain As String
Dim strUserName As String
Dim strSrcURI As String
Dim ResponseStream As System.IO.Stream
Dim sr As System.IO.StreamReader
Try
' Initialize variables.
strUserName = "user"
strPassword = "password"
strDomain = "domain"
strSrcURI =
"http://servername/exchange/user/inbox/testattach123.eml"
' Create a new CredentialCache object and fill it with the
network
' credentials required to access the server.
MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(strSrcURI), _
"NTLM", _
New System.Net.NetworkCredential(strUserName, strPassword,
strDomain) _
)
' Create the HttpWebRequest object.
Request = CType(System.Net.WebRequest.Create(strSrcURI), _
System.Net.HttpWebRequest)
' Add the network credentials to the request.
Request.Credentials = MyCredentialCache
' Specify the GET method.
Request.Method = "GET"
' Set the Translate header.
Request.Headers.Add("Translate", "f")
' Send the GET method request and get the
' response from the server.
Response = CType(Request.GetResponse(),
System.Net.HttpWebResponse)
' Display the item's stream content type and length.
Console.WriteLine("Content type: " & Response.ContentType)
Console.WriteLine("Content length: " & Response.ContentLength)
' Create the stream reader object with the
' response stream.
ResponseStream = Response.GetResponseStream()
sr = New System.IO.StreamReader(ResponseStream, _
System.Text.Encoding.UTF8)
' Display the item's stream.
Console.WriteLine("")
' Dim ecEncoding As New System.Text.ASCIIEncoding()
Dim msStream As New ADODB.Stream()
Dim attachment As CDO.IBodyPart
msStream.Open(System.Reflection.Missing.Value,
ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "")
msStream.Type = ADODB.StreamTypeEnum.adTypeText
msStream.Charset = "x-ansi"
msStream.WriteText(sr.ReadToEnd(),
ADODB.StreamWriteEnum.adWriteChar)
msStream.Position = 0
msStream.Type = ADODB.StreamTypeEnum.adTypeText
Dim cdMessage As New CDO.MessageClass()
cdMessage.DataSource.OpenObject(msStream, "_Stream")
Console.WriteLine("Mail From:" &
cdMessage.Fields("urn:schemas:httpmail:fromemail").Value.ToString())
For Each attachment In cdMessage.Attachments
attachment.SaveToFile("c:\temp\" & attachment.FileName)
Next
' Clean up.
Response.Close()
ResponseStream.Close()
sr.Close()
Catch ex As Exception
' Catch any exceptions. Any error codes from the
' GET method requests on the server will be caught
' here, also.
Console.WriteLine(ex.Message)
End Try
End Sub
End Module
"josephine" wrote in message @microsoft.com...
> thanks again Glen for your help.
>
> sorry, bit confused here,
> as you stated my first code wasnt the right direction, and suggested the
> WebDav101 as reference.
>
> last suggested code falls on "Rec.Send StrQuery".
>
> have also realised that sResponse will hold body of e-mail in it;
> is this a good way to go on for "Create txt file from e-mail body"???
>
> HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> HttpWebRequest.setRequestHeader("Translate:", "f")
> HttpWebRequest.Send()
> sResponse = HttpWebRequest.ResponseText ' Returns as text
> Create_File(Date.Today, sResponse)
>
> missing the SaveAs functionality for the attachment.
>
> "Glen Scales [MVP]" wrote:
>
>> You can get the email address of the sender from the
>> urn:schemas:httpmail:fromemail property
>>
>> to download an attachment something like
>>
>> server = "servername"
>> mailbox = "mailbox"
>> set fso = createobject("Scripting.FileSystemObject")
>> strURL = "http://" & server & "/exchange/" & mailbox & "/inbox/"
>> strURL1 = "http://" & server & "/exchange/" & mailbox & "/sent items/"
>> strQuery = ""
>> strQuery = strQuery & "SELECT ""DAV:displayname"",
>> ""urn:schemas:httpmail:subject"""
>> strQuery = strQuery & " FROM scope('shallow traversal of """
>> strQuery = strQuery & strURL & """') Where ""DAV:ishidden"" = False AND
>> ""DAV:isfolder"" = False AND "
>> strQuery = strQuery & """urn:schemas:httpmail:read"" = false AND "
>> strQuery = strQuery & """urn:schemas:httpmail:hasattachment"" = True
>> "
>> set req = createobject("microsoft.xmlhttp")
>> req.open "SEARCH", strURL, false
>> req.setrequestheader "Content-Type", "text/xml"
>> req.setRequestHeader "Translate","f"
>> req.send strQuery
>> If req.status >= 500 Then
>> ElseIf req.status = 207 Then
>> set oResponseDoc = req.responseXML
>> set oNodeList = oResponseDoc.getElementsByTagName("a:displayname")
>> set oNodeList1 = oResponseDoc.getElementsByTagName("a:href")
>> For i = 0 To (oNodeList.length -1)
>> set oNode = oNodeList.nextNode
>> set oNode1 = oNodeList1.nextNode
>> wscript.echo oNode.Text
>> embedattach(oNode1.Text)
>> Next
>> Else
>> End If
>>
>> function embedattach(objhref)
>> req.open "X-MS-ENUMATTS", objhref, false, "", ""
>> req.send
>> If req.status > 207 Or req.status < 207 Then
>> wscript.echo "Status: " & req.status
>> wscript.echo "Status text: " & req.statustext
>> wscript.echo "Response text: " & req.responsetext
>> Else
>> wscript.echo ""
>> wscript.echo "Attachment"
>> set resDoc1 = req.responseXML
>> Set objPropstatNodeList1 = resDoc1.getElementsByTagName("a:propstat")
>> Set objHrefNodeList1 = resDoc1.getElementsByTagName("a:href")
>> If objPropstatNodeList1.length > 0 Then
>> wscript.echo objPropstatNodeList1.length & " attachments
>> found..."
>> For f = 0 To (objPropstatNodeList1.length -1)
>> set objPropstatNode1 = objPropstatNodeList1.nextNode
>> set objHrefNode1 = objHrefNodeList1.nextNode
>> wscript.echo "Attachment: " & objHrefNode1.Text
>> set objNodef =
>> objPropstatNode1.selectSingleNode("a:prop/d:x37050003")
>> wscript.echo "Attachment Method: " & objNodef.Text
>> set objNodef2 = objPropstatNode1.selectSingleNode("a:prop/f:cn")
>> wscript.echo "CN: " & objNodef2.Text
>> if objNodef.Text = 5 then
>> embedattach(objHrefNode1.Text)
>> else
>> set objNode1f =
>> objPropstatNode1.selectSingleNode("a:prop/d:x3704001f")
>> wscript.echo "Attachment name: " & objNode1f.Text
>> req.open "GET", objHrefNode1.Text, false, "", ""
>> req.send
>> set stm = createobject("ADODB.Stream")
>> stm.open
>> msgstring = req.responsetext
>> stm.type = 2
>> stm.Charset = "x-ansi"
>> stm.writetext msgstring,0
>> stm.Position = 0
>> stm.type = 1
>> stm.savetofile "c:\temp\" & objNode1f.Text,2
>> set stm = nothing
>> end if
>> next
>> Else
>> wscript.echo "No file attachments found..."
>> End If
>> End If
>> wscript.echo
>> end function
>>
>> Cheers
>> Glen
>>
>> "josephine" wrote in message
>> @microsoft.com...
>> > back here Glen.
>> > cant seem to get actual e-mail (again..).
>> >
>> > JOBS:
>> > iterate through e-mail body, create txt file.
>> > save attachment to a network folder.
>> >
>> > code:
>> > Dim sHREF As String
>> > Dim sResponse As String
>> > Dim HttpWebRequest
>> > Dim sUserName As String = "DOMAIN\UserName"
>> > Dim sPassword As String = "P@SSW0RD!"
>> > Dim response As String = ""
>> > sHREF = "http://MAILSERVER.com/exchange/UNmae/Inbox/"
>> > Dim mItem As String = "Finsettle ERD reports.EML"
>> > HttpWebRequest = CreateObject("microsoft.xmlhttp")
>> > sHREF = sHREF + mItem
>> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
>> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
>> > HttpWebRequest.setRequestHeader("Translate:", "f")
>> > HttpWebRequest.Send()
>> > sResponse = HttpWebRequest.ResponseText
>> >
>> > Questins PLEASE:
>> > HOWTO get e-mail body as text from sResponse???
>> > HOWTO get Attachment, save as txt from sResponse???
>>
>>
>> |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Wed Aug 01, 2007 2:52 am Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
(!)1st, and again, many thanks for your time in posting..
i think confusion is due to so many ways of implementation here.
error code was: -529697949, Source: "msxml3.dll", no Description.
couldnt find any info on this one.
what i am dealing with, are 2 kinds of e-mails;
(1)one has a 2MB Body part, to be parsed and saved to network folder.
(2)other has attachments, to be saved to network folder.
after getting data, e-mails are to be marked "Read" and moved to a folder
within inbox.
____________________________________________________________
code to get e-mail body: (is this ok?)
HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
HttpWebRequest.setRequestHeader("Translate:", "f")
HttpWebRequest.Send()
sResponse = HttpWebRequest.ResponseText
Create_File(Date.Today, sResponse)
sResponse holds e-mail body.
____________________________________________________________________
am using .Net, will look into CDOSYS +"Getting an Item's Stream".
tnx again.
kind regards,
-j.
"Glen Scales [MVP]" wrote:
> I would also suggest you have a read of the Exchange SDK as well there's is
> lot more to using webdav then just having the samples. Eg you need to work
> out first what authentication your using on your server to make sure your
> request will succeed. If you are getting an error message what is the status
> code your getting this will generally tell you what the problem is.
>
> Using a GET request will get the entire message as a RFC 822 stream (your
> attachments will be MIME encoded within the stream) you will then need to
> parse that stream to make any sense of it you could do this using something
> like CDOSYS. While this method works and is entirely valid it may or may not
> be appropriate for what you trying to do eg if you just want to pull one
> property from a message then using a Propfind on that particular property is
> easier then pulling the entire message back.
>
> If you are using .NET then I would use something like
> http://msdn2.microsoft.com/en-us/library/aa563016.aspx if you combine this
> with CDOSYS (or CDOEX) to parse the mail in question this is one method that
> should work eg
>
>
> Option Explicit On
> Option Strict On
>
> Module Module1
>
> Sub Main()
>
> ' Variables.
> Dim Request As System.Net.HttpWebRequest
> Dim Response As System.Net.HttpWebResponse
> Dim MyCredentialCache As System.Net.CredentialCache
> Dim strPassword As String
> Dim strDomain As String
> Dim strUserName As String
> Dim strSrcURI As String
> Dim ResponseStream As System.IO.Stream
> Dim sr As System.IO.StreamReader
>
> Try
> ' Initialize variables.
> strUserName = "user"
> strPassword = "password"
> strDomain = "domain"
> strSrcURI =
> "http://servername/exchange/user/inbox/testattach123.eml"
>
> ' Create a new CredentialCache object and fill it with the
> network
> ' credentials required to access the server.
> MyCredentialCache = New System.Net.CredentialCache
> MyCredentialCache.Add(New System.Uri(strSrcURI), _
> "NTLM", _
> New System.Net.NetworkCredential(strUserName, strPassword,
> strDomain) _
> )
>
> ' Create the HttpWebRequest object.
> Request = CType(System.Net.WebRequest.Create(strSrcURI), _
> System.Net.HttpWebRequest)
>
> ' Add the network credentials to the request.
> Request.Credentials = MyCredentialCache
>
> ' Specify the GET method.
> Request.Method = "GET"
>
> ' Set the Translate header.
> Request.Headers.Add("Translate", "f")
>
> ' Send the GET method request and get the
> ' response from the server.
> Response = CType(Request.GetResponse(),
> System.Net.HttpWebResponse)
>
> ' Display the item's stream content type and length.
> Console.WriteLine("Content type: " & Response.ContentType)
> Console.WriteLine("Content length: " & Response.ContentLength)
>
> ' Create the stream reader object with the
> ' response stream.
> ResponseStream = Response.GetResponseStream()
> sr = New System.IO.StreamReader(ResponseStream, _
> System.Text.Encoding.UTF8)
>
> ' Display the item's stream.
> Console.WriteLine("")
> ' Dim ecEncoding As New System.Text.ASCIIEncoding()
> Dim msStream As New ADODB.Stream()
> Dim attachment As CDO.IBodyPart
>
> msStream.Open(System.Reflection.Missing.Value,
> ADODB.ConnectModeEnum.adModeUnknown,
> ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "")
> msStream.Type = ADODB.StreamTypeEnum.adTypeText
> msStream.Charset = "x-ansi"
> msStream.WriteText(sr.ReadToEnd(),
> ADODB.StreamWriteEnum.adWriteChar)
> msStream.Position = 0
> msStream.Type = ADODB.StreamTypeEnum.adTypeText
> Dim cdMessage As New CDO.MessageClass()
> cdMessage.DataSource.OpenObject(msStream, "_Stream")
> Console.WriteLine("Mail From:" &
> cdMessage.Fields("urn:schemas:httpmail:fromemail").Value.ToString())
> For Each attachment In cdMessage.Attachments
> attachment.SaveToFile("c:\temp\" & attachment.FileName)
> Next
> ' Clean up.
> Response.Close()
> ResponseStream.Close()
> sr.Close()
>
> Catch ex As Exception
>
> ' Catch any exceptions. Any error codes from the
> ' GET method requests on the server will be caught
> ' here, also.
> Console.WriteLine(ex.Message)
>
> End Try
>
> End Sub
>
> End Module
>
> "josephine" wrote in message
> @microsoft.com...
> > thanks again Glen for your help.
> >
> > sorry, bit confused here,
> > as you stated my first code wasnt the right direction, and suggested the
> > WebDav101 as reference.
> >
> > last suggested code falls on "Rec.Send StrQuery".
> >
> > have also realised that sResponse will hold body of e-mail in it;
> > is this a good way to go on for "Create txt file from e-mail body"???
> >
> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> > HttpWebRequest.setRequestHeader("Translate:", "f")
> > HttpWebRequest.Send()
> > sResponse = HttpWebRequest.ResponseText ' Returns as text
> > Create_File(Date.Today, sResponse)
> >
> > missing the SaveAs functionality for the attachment.
> >
> > "Glen Scales [MVP]" wrote:
> >
> >> You can get the email address of the sender from the
> >> urn:schemas:httpmail:fromemail property
> >>
> >> to download an attachment something like
> >>
> >> server = "servername"
> >> mailbox = "mailbox"
> >> set fso = createobject("Scripting.FileSystemObject")
> >> strURL = "http://" & server & "/exchange/" & mailbox & "/inbox/"
> >> strURL1 = "http://" & server & "/exchange/" & mailbox & "/sent items/"
> >> strQuery = ""
> >> strQuery = strQuery & "SELECT ""DAV:displayname"",
> >> ""urn:schemas:httpmail:subject"""
> >> strQuery = strQuery & " FROM scope('shallow traversal of """
> >> strQuery = strQuery & strURL & """') Where ""DAV:ishidden"" = False AND
> >> ""DAV:isfolder"" = False AND "
> >> strQuery = strQuery & """urn:schemas:httpmail:read"" = false AND "
> >> strQuery = strQuery & """urn:schemas:httpmail:hasattachment"" = True
> >> "
> >> set req = createobject("microsoft.xmlhttp")
> >> req.open "SEARCH", strURL, false
> >> req.setrequestheader "Content-Type", "text/xml"
> >> req.setRequestHeader "Translate","f"
> >> req.send strQuery
> >> If req.status >= 500 Then
> >> ElseIf req.status = 207 Then
> >> set oResponseDoc = req.responseXML
> >> set oNodeList = oResponseDoc.getElementsByTagName("a:displayname")
> >> set oNodeList1 = oResponseDoc.getElementsByTagName("a:href")
> >> For i = 0 To (oNodeList.length -1)
> >> set oNode = oNodeList.nextNode
> >> set oNode1 = oNodeList1.nextNode
> >> wscript.echo oNode.Text
> >> embedattach(oNode1.Text)
> >> Next
> >> Else
> >> End If
> >>
> >> function embedattach(objhref)
> >> req.open "X-MS-ENUMATTS", objhref, false, "", ""
> >> req.send
> >> If req.status > 207 Or req.status < 207 Then
> >> wscript.echo "Status: " & req.status
> >> wscript.echo "Status text: " & req.statustext
> >> wscript.echo "Response text: " & req.responsetext
> >> Else
> >> wscript.echo ""
> >> wscript.echo "Attachment"
> >> set resDoc1 = req.responseXML
> >> Set objPropstatNodeList1 = resDoc1.getElementsByTagName("a:propstat")
> >> Set objHrefNodeList1 = resDoc1.getElementsByTagName("a:href")
> >> If objPropstatNodeList1.length > 0 Then
> >> wscript.echo objPropstatNodeList1.length & " attachments
> >> found..."
> >> For f = 0 To (objPropstatNodeList1.length -1)
> >> set objPropstatNode1 = objPropstatNodeList1.nextNode
> >> set objHrefNode1 = objHrefNodeList1.nextNode
> >> wscript.echo "Attachment: " & objHrefNode1.Text
> >> set objNodef =
> >> objPropstatNode1.selectSingleNode("a:prop/d:x37050003")
> >> wscript.echo "Attachment Method: " & objNodef.Text
> >> set objNodef2 = objPropstatNode1.selectSingleNode("a:prop/f:cn")
> >> wscript.echo "CN: " & objNodef2.Text
> >> if objNodef.Text = 5 then
> >> embedattach(objHrefNode1.Text)
> >> else
> >> set objNode1f =
> >> objPropstatNode1.selectSingleNode("a:prop/d:x3704001f")
> >> wscript.echo "Attachment name: " & objNode1f.Text
> >> req.open "GET", objHrefNode1.Text, false, "", ""
> >> req.send
> >> set stm = createobject("ADODB.Stream")
> >> stm.open
> >> msgstring = req.responsetext
> >> stm.type = 2
> >> stm.Charset = "x-ansi"
> >> stm.writetext msgstring,0
> >> stm.Position = 0
> >> stm.type = 1
> >> stm.savetofile "c:\temp\" & objNode1f.Text,2
> >> set stm = nothing
> >> end if
> >> next
> >> Else
> >> wscript.echo "No file attachments found..."
> >> End If
> >> End If
> >> wscript.echo
> >> end function
> >>
> >> Cheers
> >> Glen
> >>
> >> "josephine" wrote in message
> >> @microsoft.com...
> >> > back here Glen.
> >> > cant seem to get actual e-mail (again..).
> >> >
> >> > JOBS:
> >> > iterate through e-mail body, create txt file.
> >> > save attachment to a network folder.
> >> >
> >> > code:
> >> > Dim sHREF As String
> >> > Dim sResponse As String
> >> > Dim HttpWebRequest
> >> > Dim sUserName As String = "DOMAIN\UserName"
> >> > Dim sPassword As String = "P@SSW0RD!"
> >> > Dim response As String = ""
> >> > sHREF = "http://MAILSERVER.com/exchange/UNmae/Inbox/"
> >> > Dim mItem As String = "Finsettle ERD reports.EML"
> >> > HttpWebRequest = CreateObject("microsoft.xmlhttp")
> >> > sHREF = sHREF + mItem
> >> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> >> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> >> > HttpWebRequest.setRequestHeader("Translate:", "f")
> >> > HttpWebRequest.Send()
> >> > sResponse = HttpWebRequest.ResponseText
> >> >
> >> > Questins PLEASE:
> >> > HOWTO get e-mail body as text from sResponse???
> >> > HOWTO get Attachment, save as txt from sResponse???
> >>
> >>
> >>
>
>
> |
|
| Back to top |
|
 |
Glen Scales [MVP]
Joined: 05 Aug 2007 Posts: 92
|
Posted: Wed Aug 01, 2007 8:05 pm Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
Try using the code from the Exchange SDK link i sent don't use
microsoft.xmlhttp you'll get a lot more descriptive error messages and the
native classes are in general better classes to work with.
Watch out for authentication eg is your sever set to require that you use
SSL ? Are you using Forms Based Authentication in OWA ?
Cheers
Glen
"josephine" wrote in message @microsoft.com...
> (!)1st, and again, many thanks for your time in posting..
>
> i think confusion is due to so many ways of implementation here.
> error code was: -529697949, Source: "msxml3.dll", no Description.
> couldnt find any info on this one.
>
> what i am dealing with, are 2 kinds of e-mails;
> (1)one has a 2MB Body part, to be parsed and saved to network folder.
> (2)other has attachments, to be saved to network folder.
> after getting data, e-mails are to be marked "Read" and moved to a folder
> within inbox.
> ____________________________________________________________
> code to get e-mail body: (is this ok?)
> HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> HttpWebRequest.setRequestHeader("Translate:", "f")
> HttpWebRequest.Send()
> sResponse = HttpWebRequest.ResponseText
> Create_File(Date.Today, sResponse)
> sResponse holds e-mail body.
> ____________________________________________________________________
> am using .Net, will look into CDOSYS +"Getting an Item's Stream".
>
> tnx again.
> kind regards,
> -j.
>
> "Glen Scales [MVP]" wrote:
>
>> I would also suggest you have a read of the Exchange SDK as well there's
>> is
>> lot more to using webdav then just having the samples. Eg you need to
>> work
>> out first what authentication your using on your server to make sure your
>> request will succeed. If you are getting an error message what is the
>> status
>> code your getting this will generally tell you what the problem is.
>>
>> Using a GET request will get the entire message as a RFC 822 stream (your
>> attachments will be MIME encoded within the stream) you will then need to
>> parse that stream to make any sense of it you could do this using
>> something
>> like CDOSYS. While this method works and is entirely valid it may or may
>> not
>> be appropriate for what you trying to do eg if you just want to pull one
>> property from a message then using a Propfind on that particular property
>> is
>> easier then pulling the entire message back.
>>
>> If you are using .NET then I would use something like
>> http://msdn2.microsoft.com/en-us/library/aa563016.aspx if you combine
>> this
>> with CDOSYS (or CDOEX) to parse the mail in question this is one method
>> that
>> should work eg
>>
>>
>> Option Explicit On
>> Option Strict On
>>
>> Module Module1
>>
>> Sub Main()
>>
>> ' Variables.
>> Dim Request As System.Net.HttpWebRequest
>> Dim Response As System.Net.HttpWebResponse
>> Dim MyCredentialCache As System.Net.CredentialCache
>> Dim strPassword As String
>> Dim strDomain As String
>> Dim strUserName As String
>> Dim strSrcURI As String
>> Dim ResponseStream As System.IO.Stream
>> Dim sr As System.IO.StreamReader
>>
>> Try
>> ' Initialize variables.
>> strUserName = "user"
>> strPassword = "password"
>> strDomain = "domain"
>> strSrcURI =
>> "http://servername/exchange/user/inbox/testattach123.eml"
>>
>> ' Create a new CredentialCache object and fill it with the
>> network
>> ' credentials required to access the server.
>> MyCredentialCache = New System.Net.CredentialCache
>> MyCredentialCache.Add(New System.Uri(strSrcURI), _
>> "NTLM", _
>> New System.Net.NetworkCredential(strUserName,
>> strPassword,
>> strDomain) _
>> )
>>
>> ' Create the HttpWebRequest object.
>> Request = CType(System.Net.WebRequest.Create(strSrcURI), _
>> System.Net.HttpWebRequest)
>>
>> ' Add the network credentials to the request.
>> Request.Credentials = MyCredentialCache
>>
>> ' Specify the GET method.
>> Request.Method = "GET"
>>
>> ' Set the Translate header.
>> Request.Headers.Add("Translate", "f")
>>
>> ' Send the GET method request and get the
>> ' response from the server.
>> Response = CType(Request.GetResponse(),
>> System.Net.HttpWebResponse)
>>
>> ' Display the item's stream content type and length.
>> Console.WriteLine("Content type: " & Response.ContentType)
>> Console.WriteLine("Content length: " &
>> Response.ContentLength)
>>
>> ' Create the stream reader object with the
>> ' response stream.
>> ResponseStream = Response.GetResponseStream()
>> sr = New System.IO.StreamReader(ResponseStream, _
>> System.Text.Encoding.UTF8)
>>
>> ' Display the item's stream.
>> Console.WriteLine("")
>> ' Dim ecEncoding As New System.Text.ASCIIEncoding()
>> Dim msStream As New ADODB.Stream()
>> Dim attachment As CDO.IBodyPart
>>
>> msStream.Open(System.Reflection.Missing.Value,
>> ADODB.ConnectModeEnum.adModeUnknown,
>> ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "")
>> msStream.Type = ADODB.StreamTypeEnum.adTypeText
>> msStream.Charset = "x-ansi"
>> msStream.WriteText(sr.ReadToEnd(),
>> ADODB.StreamWriteEnum.adWriteChar)
>> msStream.Position = 0
>> msStream.Type = ADODB.StreamTypeEnum.adTypeText
>> Dim cdMessage As New CDO.MessageClass()
>> cdMessage.DataSource.OpenObject(msStream, "_Stream")
>> Console.WriteLine("Mail From:" &
>> cdMessage.Fields("urn:schemas:httpmail:fromemail").Value.ToString())
>> For Each attachment In cdMessage.Attachments
>> attachment.SaveToFile("c:\temp\" & attachment.FileName)
>> Next
>> ' Clean up.
>> Response.Close()
>> ResponseStream.Close()
>> sr.Close()
>>
>> Catch ex As Exception
>>
>> ' Catch any exceptions. Any error codes from the
>> ' GET method requests on the server will be caught
>> ' here, also.
>> Console.WriteLine(ex.Message)
>>
>> End Try
>>
>> End Sub
>>
>> End Module
>>
>> "josephine" wrote in message
>> @microsoft.com...
>> > thanks again Glen for your help.
>> >
>> > sorry, bit confused here,
>> > as you stated my first code wasnt the right direction, and suggested
>> > the
>> > WebDav101 as reference.
>> >
>> > last suggested code falls on "Rec.Send StrQuery".
>> >
>> > have also realised that sResponse will hold body of e-mail in it;
>> > is this a good way to go on for "Create txt file from e-mail body"???
>> >
>> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
>> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
>> > HttpWebRequest.setRequestHeader("Translate:", "f")
>> > HttpWebRequest.Send()
>> > sResponse = HttpWebRequest.ResponseText ' Returns as text
>> > Create_File(Date.Today, sResponse)
>> >
>> > missing the SaveAs functionality for the attachment.
>> >
>> > "Glen Scales [MVP]" wrote:
>> >
>> >> You can get the email address of the sender from the
>> >> urn:schemas:httpmail:fromemail property
>> >>
>> >> to download an attachment something like
>> >>
>> >> server = "servername"
>> >> mailbox = "mailbox"
>> >> set fso = createobject("Scripting.FileSystemObject")
>> >> strURL = "http://" & server & "/exchange/" & mailbox & "/inbox/"
>> >> strURL1 = "http://" & server & "/exchange/" & mailbox & "/sent items/"
>> >> strQuery = "
>> >> >"
>> >> strQuery = strQuery & "SELECT ""DAV:displayname"",
>> >> ""urn:schemas:httpmail:subject"""
>> >> strQuery = strQuery & " FROM scope('shallow traversal of """
>> >> strQuery = strQuery & strURL & """') Where ""DAV:ishidden"" = False
>> >> AND
>> >> ""DAV:isfolder"" = False AND "
>> >> strQuery = strQuery & """urn:schemas:httpmail:read"" = false AND "
>> >> strQuery = strQuery & """urn:schemas:httpmail:hasattachment"" = True
>> >> "
>> >> set req = createobject("microsoft.xmlhttp")
>> >> req.open "SEARCH", strURL, false
>> >> req.setrequestheader "Content-Type", "text/xml"
>> >> req.setRequestHeader "Translate","f"
>> >> req.send strQuery
>> >> If req.status >= 500 Then
>> >> ElseIf req.status = 207 Then
>> >> set oResponseDoc = req.responseXML
>> >> set oNodeList = oResponseDoc.getElementsByTagName("a:displayname")
>> >> set oNodeList1 = oResponseDoc.getElementsByTagName("a:href")
>> >> For i = 0 To (oNodeList.length -1)
>> >> set oNode = oNodeList.nextNode
>> >> set oNode1 = oNodeList1.nextNode
>> >> wscript.echo oNode.Text
>> >> embedattach(oNode1.Text)
>> >> Next
>> >> Else
>> >> End If
>> >>
>> >> function embedattach(objhref)
>> >> req.open "X-MS-ENUMATTS", objhref, false, "", ""
>> >> req.send
>> >> If req.status > 207 Or req.status < 207 Then
>> >> wscript.echo "Status: " & req.status
>> >> wscript.echo "Status text: " & req.statustext
>> >> wscript.echo "Response text: " & req.responsetext
>> >> Else
>> >> wscript.echo ""
>> >> wscript.echo "Attachment"
>> >> set resDoc1 = req.responseXML
>> >> Set objPropstatNodeList1 =
>> >> resDoc1.getElementsByTagName("a:propstat")
>> >> Set objHrefNodeList1 = resDoc1.getElementsByTagName("a:href")
>> >> If objPropstatNodeList1.length > 0 Then
>> >> wscript.echo objPropstatNodeList1.length & " attachments
>> >> found..."
>> >> For f = 0 To (objPropstatNodeList1.length -1)
>> >> set objPropstatNode1 = objPropstatNodeList1.nextNode
>> >> set objHrefNode1 = objHrefNodeList1.nextNode
>> >> wscript.echo "Attachment: " & objHrefNode1.Text
>> >> set objNodef =
>> >> objPropstatNode1.selectSingleNode("a:prop/d:x37050003")
>> >> wscript.echo "Attachment Method: " & objNodef.Text
>> >> set objNodef2 =
>> >> objPropstatNode1.selectSingleNode("a:prop/f:cn")
>> >> wscript.echo "CN: " & objNodef2.Text
>> >> if objNodef.Text = 5 then
>> >> embedattach(objHrefNode1.Text)
>> >> else
>> >> set objNode1f =
>> >> objPropstatNode1.selectSingleNode("a:prop/d:x3704001f")
>> >> wscript.echo "Attachment name: " & objNode1f.Text
>> >> req.open "GET", objHrefNode1.Text, false, "", ""
>> >> req.send
>> >> set stm = createobject("ADODB.Stream")
>> >> stm.open
>> >> msgstring = req.responsetext
>> >> stm.type = 2
>> >> stm.Charset = "x-ansi"
>> >> stm.writetext msgstring,0
>> >> stm.Position = 0
>> >> stm.type = 1
>> >> stm.savetofile "c:\temp\" & objNode1f.Text,2
>> >> set stm = nothing
>> >> end if
>> >> next
>> >> Else
>> >> wscript.echo "No file attachments found..."
>> >> End If
>> >> End If
>> >> wscript.echo
>> >> end function
>> >>
>> >> Cheers
>> >> Glen
>> >>
>> >> "josephine" wrote in message
>> >> @microsoft.com...
>> >> > back here Glen.
>> >> > cant seem to get actual e-mail (again..).
>> >> >
>> >> > JOBS:
>> >> > iterate through e-mail body, create txt file.
>> >> > save attachment to a network folder.
>> >> >
>> >> > code:
>> >> > Dim sHREF As String
>> >> > Dim sResponse As String
>> >> > Dim HttpWebRequest
>> >> > Dim sUserName As String = "DOMAIN\UserName"
>> >> > Dim sPassword As String = "P@SSW0RD!"
>> >> > Dim response As String = ""
>> >> > sHREF = "http://MAILSERVER.com/exchange/UNmae/Inbox/"
>> >> > Dim mItem As String = "Finsettle ERD reports.EML"
>> >> > HttpWebRequest = CreateObject("microsoft.xmlhttp")
>> >> > sHREF = sHREF + mItem
>> >> > HttpWebRequest.Open("GET", sHREF, False, sUserName,
>> >> > sPassword)
>> >> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
>> >> > HttpWebRequest.setRequestHeader("Translate:", "f")
>> >> > HttpWebRequest.Send()
>> >> > sResponse = HttpWebRequest.ResponseText
>> >> >
>> >> > Questins PLEASE:
>> >> > HOWTO get e-mail body as text from sResponse???
>> >> > HOWTO get Attachment, save as txt from sResponse???
>> >>
>> >>
>> >>
>>
>>
>> |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Wed Aug 01, 2007 3:32 am Post subject: Re: get e-mail from Response in Exchange Server 2003 |
|
|
had no authentication issues so far,
server requires SSL,
not sure which authentication i use here..
seems to work both with Credential object, and with passing u.name/password
on OPEN command; "HttpWebRequest.Open("GET", sHREF, False, sUserName,
sPassword)"
"Glen Scales [MVP]" wrote:
> Try using the code from the Exchange SDK link i sent don't use
> microsoft.xmlhttp you'll get a lot more descriptive error messages and the
> native classes are in general better classes to work with.
>
> Watch out for authentication eg is your sever set to require that you use
> SSL ? Are you using Forms Based Authentication in OWA ?
>
> Cheers
> Glen
>
>
>
> "josephine" wrote in message
> @microsoft.com...
> > (!)1st, and again, many thanks for your time in posting..
> >
> > i think confusion is due to so many ways of implementation here.
> > error code was: -529697949, Source: "msxml3.dll", no Description.
> > couldnt find any info on this one.
> >
> > what i am dealing with, are 2 kinds of e-mails;
> > (1)one has a 2MB Body part, to be parsed and saved to network folder.
> > (2)other has attachments, to be saved to network folder.
> > after getting data, e-mails are to be marked "Read" and moved to a folder
> > within inbox.
> > ____________________________________________________________
> > code to get e-mail body: (is this ok?)
> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> > HttpWebRequest.setRequestHeader("Translate:", "f")
> > HttpWebRequest.Send()
> > sResponse = HttpWebRequest.ResponseText
> > Create_File(Date.Today, sResponse)
> > sResponse holds e-mail body.
> > ____________________________________________________________________
> > am using .Net, will look into CDOSYS +"Getting an Item's Stream".
> >
> > tnx again.
> > kind regards,
> > -j.
> >
> > "Glen Scales [MVP]" wrote:
> >
> >> I would also suggest you have a read of the Exchange SDK as well there's
> >> is
> >> lot more to using webdav then just having the samples. Eg you need to
> >> work
> >> out first what authentication your using on your server to make sure your
> >> request will succeed. If you are getting an error message what is the
> >> status
> >> code your getting this will generally tell you what the problem is.
> >>
> >> Using a GET request will get the entire message as a RFC 822 stream (your
> >> attachments will be MIME encoded within the stream) you will then need to
> >> parse that stream to make any sense of it you could do this using
> >> something
> >> like CDOSYS. While this method works and is entirely valid it may or may
> >> not
> >> be appropriate for what you trying to do eg if you just want to pull one
> >> property from a message then using a Propfind on that particular property
> >> is
> >> easier then pulling the entire message back.
> >>
> >> If you are using .NET then I would use something like
> >> http://msdn2.microsoft.com/en-us/library/aa563016.aspx if you combine
> >> this
> >> with CDOSYS (or CDOEX) to parse the mail in question this is one method
> >> that
> >> should work eg
> >>
> >>
> >> Option Explicit On
> >> Option Strict On
> >>
> >> Module Module1
> >>
> >> Sub Main()
> >>
> >> ' Variables.
> >> Dim Request As System.Net.HttpWebRequest
> >> Dim Response As System.Net.HttpWebResponse
> >> Dim MyCredentialCache As System.Net.CredentialCache
> >> Dim strPassword As String
> >> Dim strDomain As String
> >> Dim strUserName As String
> >> Dim strSrcURI As String
> >> Dim ResponseStream As System.IO.Stream
> >> Dim sr As System.IO.StreamReader
> >>
> >> Try
> >> ' Initialize variables.
> >> strUserName = "user"
> >> strPassword = "password"
> >> strDomain = "domain"
> >> strSrcURI =
> >> "http://servername/exchange/user/inbox/testattach123.eml"
> >>
> >> ' Create a new CredentialCache object and fill it with the
> >> network
> >> ' credentials required to access the server.
> >> MyCredentialCache = New System.Net.CredentialCache
> >> MyCredentialCache.Add(New System.Uri(strSrcURI), _
> >> "NTLM", _
> >> New System.Net.NetworkCredential(strUserName,
> >> strPassword,
> >> strDomain) _
> >> )
> >>
> >> ' Create the HttpWebRequest object.
> >> Request = CType(System.Net.WebRequest.Create(strSrcURI), _
> >> System.Net.HttpWebRequest)
> >>
> >> ' Add the network credentials to the request.
> >> Request.Credentials = MyCredentialCache
> >>
> >> ' Specify the GET method.
> >> Request.Method = "GET"
> >>
> >> ' Set the Translate header.
> >> Request.Headers.Add("Translate", "f")
> >>
> >> ' Send the GET method request and get the
> >> ' response from the server.
> >> Response = CType(Request.GetResponse(),
> >> System.Net.HttpWebResponse)
> >>
> >> ' Display the item's stream content type and length.
> >> Console.WriteLine("Content type: " & Response.ContentType)
> >> Console.WriteLine("Content length: " &
> >> Response.ContentLength)
> >>
> >> ' Create the stream reader object with the
> >> ' response stream.
> >> ResponseStream = Response.GetResponseStream()
> >> sr = New System.IO.StreamReader(ResponseStream, _
> >> System.Text.Encoding.UTF8)
> >>
> >> ' Display the item's stream.
> >> Console.WriteLine("")
> >> ' Dim ecEncoding As New System.Text.ASCIIEncoding()
> >> Dim msStream As New ADODB.Stream()
> >> Dim attachment As CDO.IBodyPart
> >>
> >> msStream.Open(System.Reflection.Missing.Value,
> >> ADODB.ConnectModeEnum.adModeUnknown,
> >> ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "")
> >> msStream.Type = ADODB.StreamTypeEnum.adTypeText
> >> msStream.Charset = "x-ansi"
> >> msStream.WriteText(sr.ReadToEnd(),
> >> ADODB.StreamWriteEnum.adWriteChar)
> >> msStream.Position = 0
> >> msStream.Type = ADODB.StreamTypeEnum.adTypeText
> >> Dim cdMessage As New CDO.MessageClass()
> >> cdMessage.DataSource.OpenObject(msStream, "_Stream")
> >> Console.WriteLine("Mail From:" &
> >> cdMessage.Fields("urn:schemas:httpmail:fromemail").Value.ToString())
> >> For Each attachment In cdMessage.Attachments
> >> attachment.SaveToFile("c:\temp\" & attachment.FileName)
> >> Next
> >> ' Clean up.
> >> Response.Close()
> >> ResponseStream.Close()
> >> sr.Close()
> >>
> >> Catch ex As Exception
> >>
> >> ' Catch any exceptions. Any error codes from the
> >> ' GET method requests on the server will be caught
> >> ' here, also.
> >> Console.WriteLine(ex.Message)
> >>
> >> End Try
> >>
> >> End Sub
> >>
> >> End Module
> >>
> >> "josephine" wrote in message
> >> @microsoft.com...
> >> > thanks again Glen for your help.
> >> >
> >> > sorry, bit confused here,
> >> > as you stated my first code wasnt the right direction, and suggested
> >> > the
> >> > WebDav101 as reference.
> >> >
> >> > last suggested code falls on "Rec.Send StrQuery".
> >> >
> >> > have also realised that sResponse will hold body of e-mail in it;
> >> > is this a good way to go on for "Create txt file from e-mail body"???
> >> >
> >> > HttpWebRequest.Open("GET", sHREF, False, sUserName, sPassword)
> >> > HttpWebRequest.setRequestHeader("Content-type:", "text/xml")
> >> > HttpWebRequest.setRequestHeader("Translate:", "f")
> >> > HttpWebRequest.Send()
> >> > sResponse = HttpWebRequest.ResponseText ' Returns as text
> >> > Create_File(Date.Today, sResponse)
> >> >
> >> > missing the SaveAs functionality for the attachment.
> >> >
> >> > "Glen Scales [MVP]" wrote:
> >> >
> >> >> You can get the email address of the sender from the
> >> >> urn:schemas:httpmail:fromemail property
> >> >>
> >> >> to download an attachment something like
> >> >>
> >> >> server = "servername"
> >> >> mailbox = "mailbox"
> >> >> set fso = createobject("Scripting.FileSystemObject")
> >> >> strURL = "http://" & server & "/exchange/" & mailbox & "/inbox/"
> >> >> strURL1 = "http://" & server & "/exchange/" & mailbox & "/sent items/"
> >> >> strQuery = "
> >> >> >"
> >> >> strQuery = strQuery & "SELECT ""DAV:displayname"",
> >> >> ""urn:schemas:httpmail:subject"""
> >> >> strQuery = strQuery & " FROM scope('shallow traversal of """
> >> >> strQuery = strQuery & strURL & """') Where ""DAV:ishidden"" = False
> >> >> AND
> >> >> ""DAV:isfolder"" = False AND "
> >> >> strQuery = strQuery & """urn:schemas:httpmail:read"" = false AND "
> >> >> strQuery = strQuery & """urn:schemas:httpmail:hasattachment"" = True
> >> >> "
> >> >> set req = createobject("microsoft.xmlhttp")
> >> >> req.open "SEARCH", strURL, false
> >> >> req.setrequestheader "Content-Type", "text/xml"
> >> >> req.setRequestHeader "Translate","f"
> >> >> req.send strQuery
> >> >> If req.status >= 500 Then
> >> >> ElseIf req.status = 207 Then
> >> >> set oResponseDoc = req.responseXML
> >> >> set oNodeList = oResponseDoc.getElementsByTagName("a:displayname")
> >> >> set oNodeList1 = oResponseDoc.getElementsByTagName("a:href")
> >> >> For i = 0 To (oNodeList.length -1)
> >> >> set oNode = oNodeList.nextNode
> >> >> set oNode1 = oNodeList1.nextNode
> >> >> wscript.echo oNode.Text
> >> >> embedattach(oNode1.Text)
> >> >> Next
> >> >> Else
> >> >> End If
> >> >>
> >> >> function embedattach(objhref)
> >> >> req.open "X-MS-ENUMATTS", objhref, false, "", ""
> >> >> req.send
> >> >> If req.status > 207 Or req.status < 207 Then
> >> >> wscript.echo "Status: " & req.status
> >> >> wscript.echo "Status text: " & req.statustext
> >> >> wscript.echo "Response text: " & req.responsetext
> >> >> Else
> >> >> wscript.echo ""
> >> >> wscript.echo "Attachment"
> >> >> set resDoc1 = req.responseXML
> >> >> Set objPropstatNodeList1 =
> >> >> resDoc1.getElementsByTagName("a:propstat")
> >> >> Set objHrefNodeList1 = resDoc1.getElementsByTagName("a:href")
> >> >> If objPropstatNodeList1.length > 0 Then
> >> >> wscript.echo objPropstatNodeList1.length & " attachments
> >> >> found..."
> >> >> For f = 0 To (objPropstatNodeList1.length -1)
> >> >> set objPropstatNode1 = objPropstatNodeList1.nextNode
> >> >> set objHrefNode1 = objHrefNodeList1.nextNode
> >> >> wscript.echo "Attachment: " & objHrefNode1.Text
> >> >> set objNodef =
> >> >> objPropstatNode1.selectSingleNode("a:prop/d:x37050003")
> >> >> wscript.echo "Attachment Method: " & objNodef.Text
> >> >> set objNodef2 =
> >> >> objPropstatNode1.selectSingleNode("a:prop/f:cn")
> >> >> wscript.echo "CN: " & objNodef2.Text
> >> >> if objNodef.Text = 5 then
> >> >> embedattach(objHrefNode1.Text)
> >> >> else
> >> >> set objNode1f =
> >> >> objPropstatNode1.selectSingleNode("a:prop/d:x3704001f")
> >> >> wscript.echo "Attachment name: " & objNode1f.Text
> >> >> req.open "GET", objHrefNode1.Text, false, "", ""
> >> >> req.send
> >> >> set stm = createobject("ADODB.Stream")
> >> >> stm.open
> >> >> msgstring = req.responsetext
> >> >> stm.type = 2
> >> >> stm.Charset = "x-ansi"
> >> >> stm.writetext msgstring,0
> >> >> stm.Position = 0
> >> >> stm.type = 1
> >> >> stm.savetofile "c:\temp\" & objNode1f.Text,2
> >> >> set stm = nothing
> >> >> end if
> >> >> next
> >> >> Else
> >> >> wscript.echo "No file attachments found..."
> >> >> End If
> >> >> End If
> >> >> wscript.echo
> >> >> end function
> >> >>
> >> >> Cheers
> >> >> Glen
> >> >>
> >> >> "josephine" wrote in message |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Wed Aug 01, 2007 1:12 pm Post subject: RE: get e-mail from Exchange Server 2003 |
|
|
Howzit Glen..
two more questions pls, (making progress here...)
1.say my url is "http://server/exchange/user/Inbox/test.eml"
and i am running a "GET" method of HttpWebRequest.
but there are 2 e-mails named test.eml, how can i tell for sure which
one i get?
2.when sending a "SEARCH" method, SQL style, i get a "Bad Request" on a
nested query.
strQuery = "SELECT ""DAV:displayname"" FROM """ & strURL
strQuery = strQuery & """ WHERE ""DAV:ishidden"" = false AND
""DAV:isfolder"" = false AND ""urn:schemas:httpmail:read"" = false AND
""urn:schemas:mailheader:date"" = " & _
"(" & "SELECT MAX( ""urn:schemas:httpmail:date"" ) FROM """ & strURL &
""")"
(basicly,where date= max(date) from inbox)
and how from response of a "SEARCH" i drill down to "GET"???
many thanks,
regards,
-j. |
|
| Back to top |
|
 |
Glen Scales [MVP]
Joined: 05 Aug 2007 Posts: 92
|
Posted: Thu Aug 02, 2007 12:55 pm Post subject: Re: get e-mail from Exchange Server 2003 |
|
|
1. You wont have two DAV:href's that are then same Exchange will append a
number eg test-1.eml if that URL has already been assinged.
2. You can't use nested SQL queries in Exchange the actual SQL you can issue
is limited to a subset of SQL commands that are listed in the SDK
http://msdn2.microsoft.com/en-US/library/aa123647.aspx
Cheers
glen
"josephine" wrote in message @microsoft.com...
> Howzit Glen..
> two more questions pls, (making progress here...)
>
> 1.say my url is "http://server/exchange/user/Inbox/test.eml"
> and i am running a "GET" method of HttpWebRequest.
> but there are 2 e-mails named test.eml, how can i tell for sure which
> one i get?
>
> 2.when sending a "SEARCH" method, SQL style, i get a "Bad Request" on a
> nested query.
>
> strQuery = "SELECT ""DAV:displayname"" FROM """ & strURL
> strQuery = strQuery & """ WHERE ""DAV:ishidden"" = false AND
> ""DAV:isfolder"" = false AND ""urn:schemas:httpmail:read"" = false AND
> ""urn:schemas:mailheader:date"" = " & _
> "(" & "SELECT MAX( ""urn:schemas:httpmail:date"" ) FROM """ & strURL
> &
> """)"
> (basicly,where date= max(date) from inbox)
>
> and how from response of a "SEARCH" i drill down to "GET"???
>
> many thanks,
> regards,
> -j.
>
>
> |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Thu Aug 02, 2007 4:18 am Post subject: Re: get e-mail from Exchange Server 2003 |
|
|
but how do i know if initial url has latest date? i.e., last "test.eml" to be
received..
"Glen Scales [MVP]" wrote:
> 1. You wont have two DAV:href's that are then same Exchange will append a
> number eg test-1.eml if that URL has already been assinged.
>
> 2. You can't use nested SQL queries in Exchange the actual SQL you can issue
> is limited to a subset of SQL commands that are listed in the SDK
> http://msdn2.microsoft.com/en-US/library/aa123647.aspx
>
> Cheers
> glen
>
> "josephine" wrote in message
> @microsoft.com...
> > Howzit Glen..
> > two more questions pls, (making progress here...)
> >
> > 1.say my url is "http://server/exchange/user/Inbox/test.eml"
> > and i am running a "GET" method of HttpWebRequest.
> > but there are 2 e-mails named test.eml, how can i tell for sure which
> > one i get?
> >
> > 2.when sending a "SEARCH" method, SQL style, i get a "Bad Request" on a
> > nested query.
> >
> > strQuery = "SELECT ""DAV:displayname"" FROM """ & strURL
> > strQuery = strQuery & """ WHERE ""DAV:ishidden"" = false AND
> > ""DAV:isfolder"" = false AND ""urn:schemas:httpmail:read"" = false AND
> > ""urn:schemas:mailheader:date"" = " & _
> > "(" & "SELECT MAX( ""urn:schemas:httpmail:date"" ) FROM """ & strURL
> > &
> > """)"
> > (basicly,where date= max(date) from inbox)
> >
> > and how from response of a "SEARCH" i drill down to "GET"???
> >
> > many thanks,
> > regards,
> > -j.
> >
> >
> >
>
>
> |
|
| Back to top |
|
 |
josephine
Joined: 06 Aug 2007 Posts: 22
|
Posted: Thu Aug 02, 2007 10:52 am Post subject: Re: get e-mail from Exchange Server 2003 |
|
|
ok, i see, WebDAV does append a counter onto the mail.. thanks for pointing
it out for us blondies.
question pls:
you posted earlier:
"don't use microsoft.xmlhttp you'll get a lot more descriptive error
messages and the native classes are in general better classes to work with."
i use system.net.httpwebRequest\Response for saving attachments and moving
e-mails.
for a PROPPATCH method, must i use "microsoft.xmlhttp"?
can 1 app do all the above in 1 run?
thanks in advance for posting,
regards,
-j
question
"josephine" wrote:
> but how do i know if initial url has latest date? i.e., last "test.eml" to be
> received..
>
> "Glen Scales [MVP]" wrote:
>
> > 1. You wont have two DAV:href's that are then same Exchange will append a
> > number eg test-1.eml if that URL has already been assinged.
> >
> > 2. You can't use nested SQL queries in Exchange the actual SQL you can issue
> > is limited to a subset of SQL commands that are listed in the SDK
> > http://msdn2.microsoft.com/en-US/library/aa123647.aspx
> >
> > Cheers
> > glen
> >
> > "josephine" wrote in message
> > @microsoft.com...
> > > Howzit Glen..
> > > two more questions pls, (making progress here...)
> > >
> > > 1.say my url is "http://server/exchange/user/Inbox/test.eml"
> > > and i am running a "GET" method of HttpWebRequest.
> > > but there are 2 e-mails named test.eml, how can i tell for sure which
> > > one i get?
> > >
> > > 2.when sending a "SEARCH" method, SQL style, i get a "Bad Request" on a
> > > nested query.
> > >
> > > strQuery = "SELECT ""DAV:displayname"" FROM """ & strURL
> > > strQuery = strQuery & """ WHERE ""DAV:ishidden"" = false AND
> > > ""DAV:isfolder"" = false AND ""urn:schemas:httpmail:read"" = false AND
> > > ""urn:schemas:mailheader:date"" = " & _
> > > "(" & "SELECT MAX( ""urn:schemas:httpmail:date"" ) FROM """ & strURL
> > > &
> > > """)"
> > > (basicly,where date= max(date) from inbox)
> > >
> > > and how from response of a "SEARCH" i drill down to "GET"???
> > >
> > > many thanks,
> > > regards,
> > > -j.
> > >
> > >
> > >
> >
> >
> > |
|
| Back to top |
|
 |
Glen Scales [MVP]
Joined: 05 Aug 2007 Posts: 92
|
Posted: Fri Aug 03, 2007 1:46 pm Post subject: Re: get e-mail from Exchange Server 2003 |
|
|
Don't rely on that counter though you should always check the
DAV:Creationdate or simular property this will tell you when an item was
created in the store and you can then always ensure you working with the
latest version. httpwebRequest is okay for anything in WebDAV there's a
proppatch sample on http://msdn2.microsoft.com/en-us/library/aa123587.aspx.
Cheers
Glen
"josephine" wrote in message @microsoft.com...
> ok, i see, WebDAV does append a counter onto the mail.. thanks for
> pointing
> it out for us blondies.
>
> question pls:
> you posted earlier:
> "don't use microsoft.xmlhttp you'll get a lot more descriptive error
> messages and the native classes are in general better classes to work
> with."
>
> i use system.net.httpwebRequest\Response for saving attachments and moving
> e-mails.
> for a PROPPATCH method, must i use "microsoft.xmlhttp"?
> can 1 app do all the above in 1 run?
>
> thanks in advance for posting,
> regards,
> -j
>
>
> question
>
> "josephine" wrote:
>
>> but how do i know if initial url has latest date? i.e., last "test.eml"
>> to be
>> received..
>>
>> "Glen Scales [MVP]" wrote:
>>
>> > 1. You wont have two DAV:href's that are then same Exchange will append
>> > a
>> > number eg test-1.eml if that URL has already been assinged.
>> >
>> > 2. You can't use nested SQL queries in Exchange the actual SQL you can
>> > issue
>> > is limited to a subset of SQL commands that are listed in the SDK
>> > http://msdn2.microsoft.com/en-US/library/aa123647.aspx
>> >
>> > Cheers
>> > glen
>> >
>> > "josephine" wrote in message
>> > @microsoft.com...
>> > > Howzit Glen..
>> > > two more questions pls, (making progress here...)
>> > >
>> > > 1.say my url is "http://server/exchange/user/Inbox/test.eml"
>> > > and i am running a "GET" method of HttpWebRequest.
>> > > but there are 2 e-mails named test.eml, how can i tell for sure
>> > > which
>> > > one i get?
>> > >
>> > > 2.when sending a "SEARCH" method, SQL style, i get a "Bad Request"
>> > > on a
>> > > nested query.
>> > >
>> > > strQuery = "SELECT ""DAV:displayname"" FROM """ & strURL
>> > > strQuery = strQuery & """ WHERE ""DAV:ishidden"" = false AND
>> > > ""DAV:isfolder"" = false AND ""urn:schemas:httpmail:read"" = false
>> > > AND
>> > > ""urn:schemas:mailheader:date"" = " & _
>> > > "(" & "SELECT MAX( ""urn:schemas:httpmail:date"" ) FROM """ &
>> > > strURL
>> > > &
>> > > """)"
>> > > (basicly,where date= max(date) from inbox)
>> > >
>> > > and how from response of a "SEARCH" i drill down to "GET"???
>> > >
>> > > many thanks,
>> > > regards,
>> > > -j.
>> > >
>> > >
>> > >
>> >
>> >
>> >
|
|
| Back to top |
|
 |
|
|
| Related Topics: | Trap E-mails on Exchange server sent using outlook Dear All, I want to trap all e-mails on my Exchange server. My problem is that a message is sent using a MAPI client, such as Outlook , and are not trappable using OnArrival event Sink of Pls. suggest an alternative The M
Modifying security attributes on Exchange Server programmati Hi, Using the Exchange System Manager, I can choose the server whose security attributes I wish to modify ( right click a server, choose Properties, and select the "Security" tab). How is it possible to do this I tried using the IADs int
Exch 2003 VCard script stopped working after latest critical Help! I have a customer whose public web site collects lead registrations and stores them in vcard files. Then every 30 minutes a CDOEX script runs on the Exchange server system which reads in the vcard files and puts them into a public fo
[C#][Exchange] How it works? Hi, I try to use .NEt application with Exchange 2000 But I have problem. I do this example: I have an exception on: "", "", -1); The exception is: Provider cannot be found. It may not be properly
Exchange event sink I'm looking to make an event sink that will forward specific emails (by what's in the subject line) but without the original attachment. This sink would only apply to one user. I'm new at developing. If anyone could point me in the right direction, I'd |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|