Overview
The article is about reading /deleting the mails,
attachments from a remote exchange server, I faced this requirement when my
client told me to automate the reading the undeliverable mails and deleting
them after reading from his inbox without any intervention. And making an
entry into the database about all these mails.
There are many ways of accessing the exchange server like
outlook objects, CDO, MAPI, CODEX And Webdav. But webdav is only one which doesn�t
requires any configurations as such. You have to just give the webaccess to the
mail account from exchange server from which you want to read or delete mails.
References required for the project
Imports System.xml
Imports System.Xml.Xsl
Imports MSXML2
The whole project will be dependent on the MSXML2 and its methods like
.open("PROPFIND", ConnectingURL, False, UserName, PWD)
.open("DELETE", strurl, False, UserName, PWD)
.open("GET", strattachmentUrl, False, UserName, PWD)
.open("X-MS-ENUMATTS", strUrl, False, UserName, PWD)
- ConnectingURL:- Is the Path of your Exchange server
- Example:- http://255.255.255.255/exchange/administrator/inbox
- UserName:- Is the name of inbox owner
- Pwd:- Is the password of the inbox owner.
And
to implement this project you need to have sound knowledge of XML,
as the methods return results as XML. So all the manipulations is done on XML
only.
Declaring the variables
Please
ensure that MSXML2 with version of 4.0,you can download it from MSDN.
Dim oXmlHttp As New MSXML2.ServerXMLHTTP40
Dim xmlDOMParams As New System.Xml.XmlDataDocument
Dim xmlDOMParamsAttachement As New MSXML2.DOMDocument40
Dim xmlNdLstDonation, xmlNdLstDonation1,
xmlNdListHasAttach As XmlNodeList
Dim PropstatNodes As System.Xml.XmlNodeList
Dim HrefNodes As System.Xml.XmlNodeList
Dim StatusNode As System.Xml.XmlNode
Dim PropNode As System.Xml.XmlNode
With oXmlHttp
.open("PROPFIND", ConnectingURL, False, UserName, PWD)
.setRequestHeader("Depth", "1")
.setRequestHeader("Content-type", "xml")
.send()
Debug.Write(.responseBody)
Debug.Write(.responseXML)
str = oXmlHttp.responseText
xmlDOMParams.LoadXml(str)
xmlNdLstDonation = xmlDOMParams.GetElementsByTagName(
"e:textdescription")
xmlNdLstDonation1 = xmlDOMParams.GetElementsByTagName("a:href")
Relevance of the output
e:textdescription:- Gives you the body of Email
a:href:- Gives
you the path of each mail as emails are stored as EML files in exchange server.
For
example a email in your exchange server will be stored as :--
http://255.255.255.255/exchange/administrator/inbox/emailsubject.eml
d:subject:- Gives you the subject all the emails.
e:hasattachment:- Tells you whether the email contains attachment or
not.
To delete the specific email
strurl = Pass the URL of mail which
you want to delete.
http://255.255.255.255/exchange/administrator/inbox/emailsubject.eml
You can extract the names of mail
from a:href tag and pass it to this method to delete more than one mail.
.open("DELETE", strurl, False, UserName, PWD)
.setRequestHeader("Depth", "infinity")
.send()
Get the list of attachments of a mail
Public Function GetAttachmentsListXML(ByVal strUrl As String) As String
Const FOLDERITEM = "Inbox"
Dim HttpWebRequest As MSXML2.XMLHTTP40
Dim strPropReq As String
Dim strOutPutFile As String
Dim xmlAttachUrl As New MSXML2.DOMDocument40
Dim xmlNdLstDonation2 As XmlNodeList
Dim xmlNd As XmlNode
Dim GetAttachmentsListXML1 As String
Dim strURL1 As String
HttpWebRequest = New MSXML2.XMLHTTP40
With HttpWebRequest
.open("X-MS-ENUMATTS", strUrl, False, UserName, PWD)
.setRequestHeader("Depth", "1")
.setRequestHeader("Content-type", "xml")
.send()
GetAttachmentsListXML1 = HttpWebRequest.responseText
End With
HttpWebRequest = Nothing
End Function
You can parse this GetAttachmentsListXML1 (XML) to get the
path of attachment once you get the path of attachment you can pass that path
to. open("GET", strattachmentUrl, False,
UserName, PWD)
ReadAnAttatchment as string
Dim HttpWebRequest As MSXML2.XMLHTTP40
HttpWebRequest = New MSXML2.XMLHTTP40
HttpWebRequest.open("GET", strattachmentUrl, False, UserName, PWD)
HttpWebRequest.send()
ReadAnAttatchment = HttpWebRequest.responseText
Hope
this code will help you people. Happy coding.
| You must Sign In to use this message board. |
|
|
 |
|
 |
i have code that sending email via exchange server using webdav. but every sent email always save in sent folder. how to set every sent email not save in sent folder.
thanks before
Peace Out
Zigo AlCapone
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Amit Do you have any idea how can we make a new folder on exchange server directly.
Regards Usha
ushagupta
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have converted your code to C# but get a message stating: Compiler Error Message: CS1501: No overload for method 'send' takes '0' arguments when I try to run it. My code is as follows, any ideas as to how to resolve this? <pre> MSXML2.ServerXMLHTTP40 oXmlHttp = new MSXML2.ServerXMLHTTP40(); System.Xml.XmlDataDocument xmlDOMParams = new System.Xml.XmlDataDocument(); MSXML2.DOMDocument40 xmlDOMParamsAttachement = new MSXML2.DOMDocument40(); XmlNodeList xmlNdLstDonation, xmlNdLstDonation1, xmlNdListHasAttach; System.Xml.XmlNodeList PropstatNodes; System.Xml.XmlNodeList HrefNodes; System.Xml.XmlNode StatusNode; System.Xml.XmlNode PropNode; oXmlHttp.open("ProPFIND", "http://server/exchange/user/inbox", false, "userid", "password"); oXmlHttp.setRequestHeader("Depth", "1"); oXmlHttp.setRequestHeader("Content-type", "xml"); oXmlHttp.send(); Debug.Write(oXmlHttp.responseBody); Debug.Write(oXmlHttp.responseXML); str = oXmlHttp.responseText; xmlDOMParams.LoadXml(str); xmlNdLstDonation = xmlDOMParams.GetElementsByTagName("e:textdescription"); xmlNdLstDonation1 = xmlDOMParams.GetElementsByTagName("d:subject"); xmlNdLstDonation2 = xmlDOMParams.GetElementsByTagName("a:href"); xmlNdLstDonation3 = xmlDOMParams.GetElementsByTagName("e:hasattachment"); </pre>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Refer the post "C# implementation of this?" on last page of where questions have been posted. I hope this will help you
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I feel stupid asking this but where can I locate the C# implementation of this? I'm not having any luck locating it. Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I keep getting a 404 error. Our network group tries to set things up as complicated as possible. So can anyone give me tips on testing connection.
Should i be able to ping "http://255.255.255.255/exchange/administrator/inbox" after changing the ip to the correct ip and administrator to my username?
If some one could upload this project so that i can ensure that ive copied everything correctly that may help.
Again the "str = oXmlHttp.responseText" line returns a page not found.
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I solved this issue. The server URL was http://webmail.mysite.org/exchange/myname2/inbox. The user name was myname02. To understand this you need to understand how they have the email set up at my work. My user name has a 0 (zero) before the 2 but my email does not. Don't ask me why they set it up this way, but if your place your using this is the same you need to have you EMAIL (minus the @site.com) in the exchange URL but use your domain credentials for the user name and password.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
//Dim oXmlHttp As New MSXML2.ServerXMLHTTP40 MSXML2.ServerXMLHTTP40Class oXmlHttp = new ServerXMLHTTP40Class() ;
//Dim xmlDOMParams As New System.Xml.XmlDataDocument System.Xml.XmlDataDocument xmlDOMParams = new XmlDataDocument();
//Dim xmlDOMParamsAttachement As New MSXML2.DOMDocument40 MSXML2.DOMDocument40Class xmlDOMParamsAttachment = new DOMDocument40Class();
//Dim xmlNdLstDonation, xmlNdLstDonation1, // xmlNdListHasAttach As XmlNodeList XmlNodeList xmlNdLstDonation; XmlNodeList xmlNdLstDonation1; XmlNodeList xmlNdListHasAttach;
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I have an requirement of transferring pdf files from one server to the other within the intranet. But due to some network policies, the network administrators are not allowing me to transfer the files over the network shares.
I was suggested to use a standard WEBDAV for file transfers via the HTTP/HTTPs.
I am working on .net 2.0 with c# and asp.net, can you please let me know whether the transfer of files is possible using WEBDAV and if so ... can you please provide me with a sample...
Thanks in advance.
Santosh
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Santosh,
I am sorry ..not working in .net anymore ..but i think you need to re-think transfering of PDF file using web dav ( performance may be an issue if the PDF;s are of big size ).
Nothing personal if its a company requirement than you should be able to get the right approvals ( we are just talking FTP of files ).
if its ur personal requirement ..then we can think of some solution 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Amit,
As per your code I am trying to implement to get emails from exchange server. I have supplied initially exchange server url like http://myexchange.com, I got the error message like "A connection with the server could not be established", Then I tried as http://myexchange.com:port, this time I got the message like "The server returned an invalid or unrecognized response".
Then I tried as http://myexchange.com:port/developers/inbox, here developers is one user,(I have placed even administrator also in place of developers) even then also I got the same message like "The server returned an invalid or unrecognized response".
Then I tried with username and password also like oXmlHttp.open("PROPFIND", "http://myexchange.com:port/developers/inbox",false,username,password);
Eventhough I got same message like above.
Please help me where I am wrong.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Can you elaborate what you mean by email tracking ? "Read Receipt " kind of things ???
OR something similar to "123greetings.com" where they have the ability to track when the person reads the file
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Amit Thanks for reply.yes you are right.i am talking about similar to "123greetings.com" where they have the ability to track when the person reads the file.can you help me?
Thanks in Advance
ushagupta
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Usha
I have been out of touch from .net from last 3.5 yrs.. but in my opnion the 123greetings is not a email tracking its more like a site hit count.
I think how they have designed is that they maintain a "link" and "emailaddress" tag in the URL ( as card can be accessed multiple times ) and database and when it is accessed by someone they set some kind of indicator in their database saying that the e-card has been viewed.
Send yourself a card from 123 greeting
it will look like this :-
http://www.123greetings.com/view/xxxxxxxxxxxxxxxxxxxxxx
so they just see if there is an hit on this page
Let me know if that make sense. I hope this helps you
Regards Amit
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Amit Thanks for reply.But my problem is different i want to use email tracking.we use email tracking using tag myMessage.Headers.Add("Disposition-Notification-To","email address") it will notify the user and give option to user Yes/No i don't want to show alert to the user.
Regards
ushagupta
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
hi All This is really a nice article.can anybody tell me i need my mail should be auto refresh in few minutes like outlook. Thanks in advance..
ushagupta
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Were you able to find the solution to this problem if yes please post it as i think this would be interesting to know .
However , i think you can call your main program as windows service and schedule it , if thats possible there can be surely other ways to do but as of now this strike me .
Regards amit
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |
|
 |
Hi everyone,
I almost finishing my application.
My client requested me to write an application that retrieves all the users with a mailbox in a specific Domain. Then the application will cycle through all the mailboxes and check if there are attachments in there. So far so good. Finally the application copies the attachments into a Shared Folder (Also good in here) and deletes the attachment (also working). Now comes the dodgy part, after copying the attachment to the shared folder I want the code to edit the email body and add the link to of the shared folder. I am using Webdav + MSXML to do this. I know that to retrieve the Body of the email I need to refer the Tag e:textdescription. The question is how to I Post this after editing it?
Thank you for your time.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Ok I found the solution.
I need to get some sleep.
The problem was that I was using the wrong schema Urn
Dim XMLreq As MSXML2.XMLHTTP40 XMLreq = CreateObject("Msxml2.XMLHTTP.4.0")
Dim XMLreq As MSXML2.XMLHTTP40 XMLreq = CreateObject("Msxml2.XMLHTTP.4.0")
XMLreq.open("PROPPATCH", "http://localhost/exchange/administrator/inbox/teste-4.eml", False, "Administrator", "xxxxxx")
XMLreq.setRequestHeader("Content-Type", "text/xml")
sReq = "" sReq = sReq & "DAV:" xmlns:m="http://schemas.microsoft.com/mapi/proptag/">" sReq = sReq & "" sReq = sReq & "" & item.InnerText & "" sReq = sReq & ""
XMLreq.send(sReq)
Just sharing the code in case someone needs it.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|