Click here to Skip to main content
Click here to Skip to main content

Using Exchange 2003 with Webdav (Send, Retrieve, Attachments, Contacts, Mailboxsize, Mark as Read)

By , 18 Sep 2009
 

Introduction

This article describes how to use WebDav to communicate with a Microsoft 2003 Exchange Server in order to perform several mail actions. The actions described should be a good enough basis for a programmer to (if needed) write additional actions.

This project was developed using VS2008, in C# .NET 3.5.

Background

I needed to write an application which could retrieve attachments from unread emails, download them and then mark the emails as read. Sounds easy, right? Just POP the mail, do your stuff and there you are... NOT!

The first problem was getting the attachments from the email. There are solutions available on the web, but I found out that they generated too many unexpected weird errors.
The second problem was that you can't mark an email as read. The only way is to maintain a local list with read emails, or maintain a list on a database somewhere.

So I searched for an alternative way and found WebDav. Unfortunately WebDav is very badly documented on the web and good example projects are hard to find. Therefore I composed this "How To" article containing a lot of WebDav examples.

Using the Code

When examining the downloadable source code and running the application, you might find out that you have to download MSXML 4.0 from Microsoft (the downloadable application contains the interop DLL).

The application is able to perform the following tasks:

  • Get an XMLDocument containing all unread mail URLs
  • Get an XMLDocument containing all unread mail URLs containing attachments
  • Get an XMLDocument containing a list of URLs for all attachments in one email
  • Retrieve an attachment from an email in a streamreader (displayed as string)
  • Mark an email as read
  • Get an XMLDocument with information about all folders in your mailbox
  • Get the total size of your mailbox
  • Retrieve contact information from your Exchange Contacts
  • Send an email using your exchange account

All the above actions are included in the mail.cs class file. When initiating an action, an instance of this class is started and filled with the exchange information you entered in the Exchange Settings part:

mail = new Mail();
mail.p_strServer = Properties.Settings.Default["ExchangeServer"].ToString();
mail.p_strUserName = Properties.Settings.Default["UserName"].ToString();
mail.p_strAlias = Properties.Settings.Default["UserNameAlias"].ToString();
mail.p_strPassword = Properties.Settings.Default["Password"].ToString();
mail.p_strInboxURL = Properties.Settings.Default["InboxName"].ToString();
mail.p_strDrafts = Properties.Settings.Default["DraftsName"].ToString();

Below, you can see the content of the entire mail.cs class:

class Mail
    {
        public string p_strUserName;
        public string p_strPassword;
        public string p_strAlias;
        public string p_strInboxURL;
        public string p_strServer;
        public string p_strDrafts;
        
        /// <summary>
        /// Gets an XMLDocument containing a list of attachments, found in an email
        /// </summary>
        /// <param name="strMailUrl"></param>
        /// <returns></returns>
        public XmlDocument GetAttachmentsListXML(string strMailUrl)
        {
            XmlDocument loXmlDoc = new XmlDocument();
            try
            {
                MSXML2.XMLHTTP40 HttpWebRequest = default(MSXML2.XMLHTTP40);
                HttpWebRequest = new MSXML2.XMLHTTP40();
                HttpWebRequest.open("X-MS-ENUMATTS", strMailUrl, 
				false, p_strUserName, p_strPassword);
                HttpWebRequest.setRequestHeader("Depth", "1");
                HttpWebRequest.setRequestHeader("Content-type", "xml");
                HttpWebRequest.send("");
                loXmlDoc.LoadXml(HttpWebRequest.responseText);
                HttpWebRequest = null;
            }
            catch (Exception ex)
            {
                throw;
            }
            return loXmlDoc;
        }
        /// <summary>
        /// Extracts an attachment from an email
        /// </summary>
        /// <param name="sAttachmentUrl"></param>
        /// <returns></returns>
        public string getAttachmentFromMail(string sAttachmentUrl)
        {
            string strResult = "";
            try
            {
                MSXML2.XMLHTTP40 HttpWebRequest = default(MSXML2.XMLHTTP40);
                HttpWebRequest = new MSXML2.XMLHTTP40();
                HttpWebRequest.open("GET", sAttachmentUrl, false, 
				p_strUserName, p_strPassword);
                HttpWebRequest.send("");
                strResult = HttpWebRequest.responseText;
                HttpWebRequest = null;
            }
            catch
            {
                throw;
            }
            return strResult;
        }
        /// <summary>
        /// Gets all unread email messages, containing at least one attachment, 
        /// from an email account on an exchange server
        /// </summary>
        /// <returns></returns>
        public XmlDocument GetUnreadMailWithAttachments()
        {
            HttpWebRequest loRequest = default(HttpWebRequest);
            HttpWebResponse loResponse = default(HttpWebResponse);
            string lsRootUri = null;
            string lsQuery = null;
            byte[] laBytes = null;
            Stream loRequestStream = default(Stream);
            Stream loResponseStream = default(Stream);
            XmlDocument loXmlDoc = default(XmlDocument);
            loXmlDoc = new XmlDocument();
            try
            {
                lsRootUri = p_strServer + "/Exchange/" + 
			p_strAlias + "/" + p_strInboxURL;
                lsQuery = "<?xml version=\"1.0\"?>"
                            + "<D:searchrequest xmlns:D = \"DAV:\" 
				xmlns:m=\"urn:schemas:httpmail:\">"
                            + "<D:sql>SELECT \"urn:schemas:httpmail:hasattachment\", 
				\"DAV:displayname\", "
                            + "\"urn:schemas:httpmail:from\", 
				\"urn:schemas:httpmail:subject\", "
                            + "\"urn:schemas:httpmail:htmldescription\" 
				FROM \"" + lsRootUri 
                            + "\" WHERE \"DAV:ishidden\" = false 
				AND \"DAV:isfolder\" = false AND "
                            + "\"urn:schemas:httpmail:hasattachment\" = true 
				AND \"urn:schemas:httpmail:read\" = false"
                            + "</D:sql></D:searchrequest>";
                loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
                loRequest.Credentials = new NetworkCredential
					(p_strUserName, p_strPassword);
                loRequest.Method = "SEARCH";
                laBytes = System.Text.Encoding.UTF8.GetBytes(lsQuery);
                loRequest.ContentLength = laBytes.Length;
                loRequestStream = loRequest.GetRequestStream();
                loRequestStream.Write(laBytes, 0, laBytes.Length);
                loRequestStream.Close();
                loRequest.ContentType = "text/xml";
                loRequest.Headers.Add("Translate", "F");
                loResponse = (HttpWebResponse)loRequest.GetResponse();
                loResponseStream = loResponse.GetResponseStream();
                loXmlDoc.Load(loResponseStream);
                loResponseStream.Close();
            }
            catch (Exception ex)
            {
                throw;
            }
            return loXmlDoc;
        }
        /// <summary>
        /// Gets all unread email messages from an email account on an exchange server
        /// </summary>
        /// <returns></returns>
        public XmlDocument GetUnreadMailAll()
        {
            HttpWebRequest loRequest = default(HttpWebRequest);
            HttpWebResponse loResponse = default(HttpWebResponse);
            string lsRootUri = null;
            string lsQuery = null;
            byte[] laBytes = null;
            Stream loRequestStream = default(Stream);
            Stream loResponseStream = default(Stream);
            XmlDocument loXmlDoc = default(XmlDocument);
            loXmlDoc = new XmlDocument();
            try
            {
                lsRootUri = p_strServer + "/Exchange/" + 
			p_strAlias + "/" + p_strInboxURL;
                lsQuery = "<?xml version=\"1.0\"?>"
                            + "<D:searchrequest xmlns:D = \"DAV:\" 
				xmlns:m=\"urn:schemas:httpmail:\">"
                            + "<D:sql>SELECT \"urn:schemas:httpmail:hasattachment\", 
				\"DAV:displayname\", "
                            + "\"urn:schemas:httpmail:from\", 
				\"urn:schemas:httpmail:subject\", "
                            + "\"urn:schemas:httpmail:htmldescription\" 
				FROM \"" + lsRootUri
                            + "\" WHERE \"DAV:ishidden\" = false "
                            + "AND \"DAV:isfolder\" = false " 
                            //+ "AND \"urn:schemas:httpmail:hasattachment\" = true "
                            + "AND \"urn:schemas:httpmail:read\" = false"
                            + "</D:sql></D:searchrequest>";
                loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
                loRequest.Credentials = new NetworkCredential
					(p_strUserName, p_strPassword);
                loRequest.Method = "SEARCH";
                laBytes = System.Text.Encoding.UTF8.GetBytes(lsQuery);
                loRequest.ContentLength = laBytes.Length;
                loRequestStream = loRequest.GetRequestStream();
                loRequestStream.Write(laBytes, 0, laBytes.Length);
                loRequestStream.Close();
                loRequest.ContentType = "text/xml";
                loRequest.Headers.Add("Translate", "F");
                loResponse = (HttpWebResponse)loRequest.GetResponse();
                loResponseStream = loResponse.GetResponseStream();
                loXmlDoc.Load(loResponseStream);
                loResponseStream.Close();
            }
            catch (Exception ex)
            {
                throw;
            }
            return loXmlDoc;
        }
        /// <summary>
        /// Returns information about all mailboxes
        /// </summary>
        /// <returns></returns>
        public XmlDocument GetAllMailboxInfo()
        {
            XmlDocument loXmlDoc = new XmlDocument();
            
            string lsRootUri = p_strServer + "/Exchange/" + 
				p_strAlias + "/" + p_strInboxURL;
            byte[] buffer = GetFolderSizeRequest(lsRootUri);
            var request = (HttpWebRequest)WebRequest.Create(lsRootUri);
            request.Method = "SEARCH";
            request.ContentType = "text/xml";
            request.Credentials = new NetworkCredential(p_strUserName, p_strPassword);
            request.Headers.Add("Translate", "f");
            request.Headers.Add("Depth", "1");
            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(buffer, 0, buffer.Length);
            }
            HttpWebResponse loResponse = (HttpWebResponse)request.GetResponse();
            Stream loResponseStream = loResponse.GetResponseStream();
            loXmlDoc.Load(loResponseStream);
            return loXmlDoc;
        }
        /// <summary>
        /// Helper class
        /// </summary>
        /// <returns></returns>
        public long GetMailboxSize()
        {
            return GetMailboxSize(p_strServer + "/Exchange/" + 
				p_strAlias + "/" + p_strInboxURL);
        }
        /// <summary>
        /// Returns the total size of all mailboxes 
        /// within the root node of a mailbox URL
        /// </summary>
        /// <param name="lsRootUri"></param>
        /// <returns></returns>
        private long GetMailboxSize(string lsRootUri)
        {
            XmlReader reader;
            byte[] buffer = GetFolderSizeRequest(lsRootUri);
            var request = (HttpWebRequest) WebRequest.Create(lsRootUri);
            request.Method = "SEARCH";
            request.ContentType = "text/xml";
            request.Credentials = new NetworkCredential(p_strUserName, p_strPassword);
            request.Headers.Add("Translate", "f");  
            request.Headers.Add("Depth", "1");
            using (Stream stream = request.GetRequestStream()) 
            {
                stream.Write(buffer, 0, buffer.Length); 
            }  
            using (WebResponse response = request.GetResponse()) 
            {  
                string content = new StreamReader
				(response.GetResponseStream()).ReadToEnd();  
                reader = XmlReader.Create(new StringReader(content));  
                var nsmgr = new XmlNamespaceManager(reader.NameTable);
                nsmgr.AddNamespace("dav", "DAV:");
                nsmgr.AddNamespace("e", "http://schemas.microsoft.com/mapi/proptag/");  
                var doc = new XPathDocument(reader);  
                long result = 0;  
                foreach (XPathNavigator element in doc.CreateNavigator().Select
	       ("//dav:response[dav:propstat/dav:status = 'HTTP/1.1 200 OK']", nsmgr))  
                {  
                    var size = element.SelectSingleNode
			("dav:propstat/dav:prop/e:x0e080014", nsmgr).ValueAsLong; 
                    string folderUrl = element.SelectSingleNode("dav:href", nsmgr).Value; 
                    result += size; 
                    bool hasSubs = element.SelectSingleNode
			("dav:propstat/dav:prop/dav:hassubs", nsmgr).ValueAsBoolean; 
                    if (hasSubs)  
                    {
                        result += GetMailboxSize(folderUrl);  
                    }  
                }  
                return result;  
            }  
        }
        /// <summary>
        /// Returns the size of one mail folder
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private byte[] GetFolderSizeRequest(string sUrl)  
        { 
            var settings = new XmlWriterSettings {Encoding = Encoding.UTF8}; 
            using (var stream = new MemoryStream()) 
            using (XmlWriter writer = XmlWriter.Create(stream, settings)) 
            {
                writer.WriteStartElement("searchrequest", "DAV:");  
                var searchRequest = new StringBuilder();  
                searchRequest.AppendFormat
		("SELECT \"http://schemas.microsoft.com/mapi/proptag/x0e080014\", 
            \"DAV:hassubs\" FROM SCOPE ('HIERARCHICAL TRAVERSAL OF \"{0}\"')", sUrl);  
                writer.WriteElementString("sql", searchRequest.ToString());  
                writer.WriteEndElement();  
                writer.WriteEndDocument();  
                writer.Flush();  
                return stream.ToArray(); 
            }  
        }
        /// <summary>
        /// Marks an email an read
        /// </summary>
        /// <param name="strMailUrl"></param>
        internal string MarkAsRead(string strMailUrl)
        {
            string strResult = "";
            HttpWebRequest loRequest = default(HttpWebRequest);
            HttpWebResponse loResponse = default(HttpWebResponse);
            string lsQuery = null;
            byte[] laBytes = null;
            Stream loRequestStream = default(Stream);
            XmlDocument loXmlDoc = default(XmlDocument);
            loXmlDoc = new XmlDocument();
            try
            {
                lsQuery = "<?xml version=\"1.0\"?>"
                        + "<a:propertyupdate xmlns:a=\"DAV:\" 
			xmlns:d=\"urn:schemas-microsoft-com:exch-data:\" "
                        + "xmlns:b=\"urn:schemas:httpmail:\" xmlns:c=\"xml:\">"
                        + "<a:set><a:prop><b:read>" + 1
                        + "</b:read></a:prop>"
                        + "</a:set></a:propertyupdate>";
                loRequest = (HttpWebRequest)HttpWebRequest.Create(strMailUrl);
                loRequest.Credentials = new NetworkCredential
					(p_strUserName, p_strPassword);
                loRequest.Method = "PROPPATCH";
                laBytes = Encoding.UTF8.GetBytes((string)lsQuery);
                loRequest.ContentLength = laBytes.Length;
                loRequestStream = loRequest.GetRequestStream();
                loRequestStream.Write(laBytes, 0, laBytes.Length);
                loRequestStream.Close();
                loRequest.ContentType = "text/xml";
                loResponse = (HttpWebResponse)loRequest.GetResponse();
                strResult = loResponse.StatusCode.ToString();
                loRequest = null;
                loResponse = null;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                loXmlDoc = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return strResult;
        }
        /// <summary>
        /// Sending an email
        /// </summary>
        /// <param name="strSendTo"></param>
        /// <param name="strSendSubject"></param>
        /// <param name="strSendBody"></param>
        internal string SendMail(string strSendTo, 
		string strSendSubject, string strSendBody)
        {
            HttpWebRequest PUTRequest = default(HttpWebRequest);
            WebResponse PUTResponse = default(WebResponse);
            HttpWebRequest MOVERequest = default(HttpWebRequest);
            WebResponse MOVEResponse = default(WebResponse);
            string strMailboxURI = "";
            string strSubURI = "";
            string strTempURI = "";
            string strTo = strSendTo;
            string strSubject = strSendSubject;
            string strText = strSendBody;
            string strBody = "";
            byte[] bytes = null;
            Stream PUTRequestStream = null;
            try
            {
                strMailboxURI = p_strServer + "/exchange/" + p_strAlias;
                strSubURI = p_strServer + "/exchange/" + p_strAlias
                          + "/##DavMailSubmissionURI##/";
                strTempURI = p_strServer + "/exchange/" + p_strAlias
                           + "/" + p_strDrafts + "/" + strSubject + ".eml";
                strBody = "To: " + strTo + "\n" +
                "Subject: " + strSubject + "\n" +
                "Date: " + System.DateTime.Now +
                "X-Mailer: test mailer" + "\n" +
                "MIME-Version: 1.0" + "\n" +
                "Content-Type: text/plain;" + "\n" +
                "Charset = \"iso-8859-1\"" + "\n" +
                "Content-Transfer-Encoding: 7bit" + "\n" +
                "\n" + strText;
                PUTRequest = (HttpWebRequest)HttpWebRequest.Create(strTempURI);
                PUTRequest.Credentials = new NetworkCredential
					(p_strUserName, p_strPassword);
                PUTRequest.Method = "PUT";
                bytes = Encoding.UTF8.GetBytes((string)strBody);
                PUTRequest.ContentLength = bytes.Length;
                PUTRequestStream = PUTRequest.GetRequestStream();
                PUTRequestStream.Write(bytes, 0, bytes.Length);
                PUTRequestStream.Close();
                PUTRequest.ContentType = "message/rfc822";
                PUTResponse = (HttpWebResponse)PUTRequest.GetResponse();
                MOVERequest = (HttpWebRequest)HttpWebRequest.Create(strTempURI);
                MOVERequest.Credentials = new NetworkCredential
					(p_strUserName, p_strPassword);
                MOVERequest.Method = "MOVE";
                MOVERequest.Headers.Add("Destination", strSubURI);
                MOVEResponse = (HttpWebResponse)MOVERequest.GetResponse();
                Console.WriteLine("Message successfully sent.");
                // Clean up.
                PUTResponse.Close();
                MOVEResponse.Close();
            }
            catch (Exception ex)
            {
                throw;
            }
            return strBody;
        }
        /// <summary>
        /// Returns all contacts where firstname or lastname starts 
        /// with a certain character or string
        /// </summary>
        /// <returns></returns>
        internal string PrintContactsUsingExchangeWebDAV(string strZoekString)
        {
            string sResult = "";
            NetworkCredential credentials = new NetworkCredential
					(p_strUserName, p_strPassword);
            string uri = p_strServer + "/exchange/" + p_strAlias;
            string sRequest = string.Format(
                @"<?xml version=""1.0""?>
                <g:searchrequest xmlns:g=""DAV:"">
                    <g:sql>
                        SELECT
                            ""urn:schemas:contacts:sn"", 
				""urn:schemas:contacts:givenName"",
                            ""urn:schemas:contacts:email1"", 
				""urn:schemas:contacts:telephoneNumber"", 
                            ""urn:schemas:contacts:bday"", 
				""urn:schemas:contacts:nickname"",
                            ""urn:schemas:contacts:o"", 
				""    urn:schemas:contacts:profession""
                        FROM
                            Scope('SHALLOW TRAVERSAL OF ""{0}/exchange/{1}/contacts""')
                        WHERE
                            ""urn:schemas:contacts:givenName"" LIKE '{2}%'
                        OR
                            ""urn:schemas:contacts:sn"" LIKE '{2}%'
                    </g:sql>
                </g:searchrequest>",
                p_strServer, p_strAlias, strZoekString);
            // For more contact information look up urn:schemas:contacts on MSDN
            byte[] contents = Encoding.UTF8.GetBytes(sRequest);
            HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
            request.Credentials = credentials;
            request.Method = "SEARCH";
            request.ContentLength = contents.Length;
            request.ContentType = "text/xml";
            
            using (Stream requestStream = request.GetRequestStream())
                requestStream.Write(contents, 0, contents.Length);
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            using (Stream responseStream = response.GetResponseStream())
           {
                XmlDocument document = new XmlDocument();
                document.Load(responseStream);
                foreach (XmlElement element in document.GetElementsByTagName("a:prop"))
               {
                   if (element.InnerText.Length > 0)
                   {
                       sResult = sResult + string.Format("Name:  {0} {1}\nNickname:  
			{2}\nBirthday: {3}\nEmail: {4}\nPhone: 
			{5}\nProfession:  {6}\nCompany:  {7}",
                           (element["d:givenName"] != null ? 
			element["d:givenName"].InnerText : ""),
                           (element["d:sn"] != null ? element["d:sn"].InnerText : ""),
                           (element["d:nickname"] != null ? 
			element["d:nickname"].InnerText : ""),
                           (element["d:bday"] != null ? 
			element["d:bday"].InnerText : ""),
                           (element["d:email1"] != null ? 
			element["d:email1"].InnerText : ""),
                           (element["d:telephoneNumber"] != null ? 
			element["d:telephoneNumber"].InnerText : ""),
                           (element["d:profession"] != null ? 
			element["d:profession"].InnerText : ""),
                           (element["d:o"] != null ? element["d:o"].InnerText : "")
                           ) + Environment.NewLine + Environment.NewLine;
                   }
                }
            }
            return sResult;
        }
    }

History

  • 18-09-2009 - First post of this article

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Dennis Betten
Software Developer (Senior) Sogeti B.V. Netherlands
Netherlands Netherlands
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionwebdav protocal will support Exchange 2013membersubhash2823 Apr '13 - 23:55 
webdav protocal will support Exchange 2013,
 
How to Extract outlook email attachment from Exchange server 2013,
 
which protocol should be use, either Webdav or ?
 

Please help me.it is very urgent.
GeneralMy vote of 5memberWaldemar Sauer11 Feb '13 - 11:20 
Thanks for this project. A real life saver for when you have to deal with Exchange 2003!
QuestionDo we need to poll or look for asynchronous response?memberJethro638 Jan '13 - 2:55 
Hi Dennis:
I used part of this class (SendMail) to get started sending out alert e-mails from a desktop application. It worked great and thank you for that.
 
I did notice, however, that when I used the SendMail procedure in a loop (I have a list of people that have to receive alert e-mails under certain conditions), then some of the e-mails where not being received even though the procedure executed without any problems. I had a suspicion that it had something to do with executing the procedure too quickly and something (the server maybe) was still processing one request and was not ready for the next one. I tested this by inserting a delay between calls to "SendMail" and, sure enough, that did the trick.
 
So, I started looking for something, either a status code or an asynchronous delegate that would signal that one send request was really done and it was ready to accept another. I could just leave the delay there but it will nag at me that it is really not the correct way to do it.
 
I've been looking through the documentation for HttpWebResponse and I can't seem to find anything that fits.
 
Any ideas?
Thank you again.
Mark
Question400 bad requestmemberlxai3326 Aug '12 - 19:44 
why appear 400 error bad request?
QuestionSMS from Exchange 2003memberWilsonLast20 May '12 - 20:55 
Hi,
 
Great work!
 
Hi,
 
You may also check how to send SMS from MS Exchange 2003 with Ozeki NG SMS Gateway:
sms-integration.com/p_106-ms-exchange-2003-sms.html
 
BR

QuestionWhen passing CredentialCash.DefaultCredentials() to the service getting unauthorized service errormemberAmit Mudgal18 May '12 - 2:17 
I have modified the code and tried to get the credentials from cash, but always getting the following message (Error message: The remote server returned an error: (401) Unauthorized.)
 
When we hard code the credentials it works. Can anybody please let me know what could be wrong?
 
Thanks in advance...
Amit
QuestionA working sample and throrough - you are awesomemembershwaguy26 Jan '12 - 18:37 
thank you so much!
QuestionError: 440 (Login Timeout)memberMember 804640729 Jun '11 - 13:01 
Without changing anyhting I get the error 440 (Login Timeout) when ever I try to do anything. Why does this happen and how do I fix it
AnswerRe: Error: 440 (Login Timeout)memberMember 80444226 Sep '11 - 23:42 
I have got the same error??
can anyone plz help me to figure that...
GeneralThe remote server return an error : (4000) Bad Requetsmembertanmaibk26 May '11 - 15:55 
The remote server return an error : (4000) Bad Requets When I clicked GetUnReadMail button
sd is dod sods apsd psd sasd asndpasndasd

QuestionIs not the IM address field the part of the outlook contact?memberashok.gujar15 Dec '10 - 20:50 
Hi,
 
I have used WebDAV to download the contact details from my exchange server. But I did not find IM address related field under the "urn:schemas:contacts". Is this field is part of some another namespace and if so how could we access it along with the contact details?
 
Thanks in advance,
Ashok
GeneralSearchmemberLucedoriente6 Dec '10 - 12:25 
Hi Dennis, I'm trying to develop a search metod crawling through exchange public folder and his subfolders.
Is possible using your GetUnreadMailAll and adding filters for search?
 
Thanks
 
Alessio
GeneralGrat jobmemberCannafar27 Oct '10 - 4:43 
Worked well!!
GeneralHTTP/1.0 501 Not ImplementedmemberSinaC8 Oct '10 - 2:35 
Hello,
 
When trying to get attachment within a mail. I receive the response "HTTP/1.0 501 Not Implemented" from the server. I've tried with your method and using DownloadFile method from System.Net.WebClient class, I've the same error.
Anyone knows what could be the problem ?
GeneralXmlException when getting attachment listmemberSinaC7 Oct '10 - 0:04 
Hello,
 
I'm trying to get the list of attachement found in a mail (GetAttachmentsListXml method) and a XmlException is thrown, message is: '--' is an unexpected token. The expected token is '>'. Line 81, position 5.
 
Do you have any idea of what could be the problem ? The mail I'm trying to process has one attachement.
 
Thanks
GeneralRe: XmlException when getting attachment listmemberSinaC7 Oct '10 - 0:54 
Okay, I've found the problem: Username passed to webrequest must included domain name =D
GeneralError in ApplicationmemberDeadveloper3 Aug '10 - 9:02 
When I try to 'get the list of attachments from an email' I get an error.
 
Retrieving the COM class factory for component with CLSID {88D969C5-F192-11D4-A65F-0040963251E5} failed due to the following error: 80040154.
 
Can you tell me why?
GeneralRe: Error in Applicationmemberluisxvarg23 Aug '10 - 23:19 
I get the same error. This code no works
GeneralRe: Error in Applicationmemberdockell9 Nov '10 - 7:35 
If you're building this on a 64-bit machine, try setting the Platform Target to x86 (under Project->Properties->Build).
GeneralMy vote of 4memberFoyus5 Jul '10 - 2:04 
Very good article, it's rare on this subject.
GeneralFBAmemberMember 476694226 Apr '10 - 22:32 
With Form Based Authentication turned on, I am getting a (400) Bad Request being returned as a response.
GeneralRe: FBAmemberchrismo11122 May '11 - 14:43 
For anyone with this problem, take a look at the 'DoFormbasedAuthentication' method in this article:
http://www.infinitec.de/post/2004/12/Access-the-Exchange-store-via-WebDAV-with-Form-Based-Authentication-turned-on-Updated.aspx
GeneralThanx for the base code!!memberMember 8469629 Nov '09 - 4:38 
But to get this application working i have to create a cookie etc....
 
I search on msdn and found the AuthenticateSecureOWA method....
 
So now i keep the request alive and i can read my mailbox...
General422 Unprocessable Entity in SEARCH Methodmemberfabry7315 Oct '09 - 23:27 
Hi,
I keep receiving the following exception:
422 Unprocessable Entity
 
the searchrequest is:
 
<?xml version="1.0" encoding="utf-8"?>
<searchrequest xmlns="DAV:">
  <sql>SELECT "urn:schemas:httpmail:sender",
  "urn:schemas:httpmail:from", "urn:schemas:httpmail:to",
  "urn:schemas:httpmail:cc",
  "http://schemas.microsoft.com/mapi/proptag/xe02001f",
  "urn:schemas:httpmail:replyto",
  "http://schemas.microsoft.com/mapi/proptag/x710102",
  "http://schemas.microsoft.com/mapi/proptag/x63000b",
  "http://schemas.microsoft.com/mapi/proptag/x29000b",
  "http://schemas.microsoft.com/mapi/proptag/x23000b",
  "http://schemas.microsoft.com/mapi/proptag/x70001f",
  "http://schemas.microsoft.com/mapi/proptag/x1035001f",
  "http://schemas.microsoft.com/mapi/proptag/x1039001f",
  "http://schemas.microsoft.com/mapi/proptag/x40760003",
  "http://schemas.microsoft.com/mapi/proptag/x7d001f",
  "http://schemas.microsoft.com/mapi/proptag/xfff0102",
  "DAV:contentclass", "DAV:getlastmodified",
  "http://schemas.microsoft.com/exchange/outlookmessageclass",
  "urn:schemas:httpmail:subject",
  "http://schemas.microsoft.com/exchange/sensitivity",
  "urn:schemas:httpmail:datereceived",
  "http://schemas.microsoft.com/mapi/proptag/xe080003",
  "http://schemas.microsoft.com/exchange/keywords-utf8",
  "http://schemas.microsoft.com/mapi/proptag/x260003",
  "http://schemas.microsoft.com/mapi/proptag/x170003",
  "http://schemas.microsoft.com/mapi/proptag/x1042001f",
  "urn:schemas:httpmail:submitted",
  "http://schemas.microsoft.com/mapi/proptag/x1000001f",
  "http://schemas.microsoft.com/mapi/proptag/x1013001f",
  "http://schemas.microsoft.com/mapi/proptag/xe070003",
  "http://schemas.microsoft.com/mapi/proptag/x390040",
  "http://schemas.microsoft.com/mapi/proptag/x30070040",
  "http://schemas.microsoft.com/mapi/proptag/x50001f",
  "http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8502",
  "http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8503",
  "http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8501",
  "http://schemas.microsoft.com/mapi/proptag/xe1b000b",
  "http://schemas.microsoft.com/mapi/proptag/x10810003",
  "http://schemas.microsoft.com/mapi/proptag/x10820040",
  "http://schemas.microsoft.com/mapi/proptag/x10800003",
  "http://schemas.microsoft.com/mapi/proptag/x7d001f" FROM SCOPE
  ('Shallow TRAVERSAL OF
  "http://danubecrm.crmdomain.com/exchange/ben@crmdomain.com/Posta
  in arrivo"') WHERE "DAV:isfolder" = CAST("false" AS
  "boolean")</sql>
</searchrequest>
 

how I can fix it?
 
Thanks in advance.
Kind regards,
GeneralRe: 422 Unprocessable Entity in SEARCH MethodmemberDennis Betten15 Oct '09 - 23:50 
Hi Fabry73,
 
I'm afraid I'm not able to help you. My knowledge of WebDav is not good enough.
 
I did notice know you can use "DAV:isfolder" = false instead of "DAV:isfolder" = CAST("false" AS "boolean")
 
If you find a solution to your problem, please let me know!
 
Dennis

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 18 Sep 2009
Article Copyright 2009 by Dennis Betten
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid