title: Read Exchange Server 2003 account emails
body: <p>Working on application that reads emails.
  Is there a way besides webdav to get all emails from exchange server 2003 to my local machine. 
  The problem with webdav is that it does not get's the body of Undelivered emails.</p>
  
  <pre><code>CredentialCache creds = new CredentialCache();
              creds.Add(new Uri(a), "NTLM",
                  new NetworkCredential("xxxxx", "xxxxxx", "xxxxx.com"));
  
              List&lt;Mail&gt; unreadMail = new List&lt;Mail&gt;();
              string reqStr =
  
              @"&lt;?xml version=""1.0""?&gt;
                  &lt;g:searchrequest xmlns:g=""DAV:""&gt;
                      &lt;g:sql&gt;
                          SELECT
                              ""urn:schemas:mailheader:from"",
                              ""urn:schemas:mailheader:to"",
                              ""urn:schemas:httpmail:textdescription""
  
                          FROM
                              ""http://xxxx.com/exchange/xxxx/Inbox/""
                          WHERE  
  
                               ""urn:schemas:httpmail:subject"" = 'Undeliverable: xxxx'                               
  
                          &lt;/g:sql&gt;
                  &lt;/g:searchrequest&gt;";
  
  
  
              byte[] reqBytes = Encoding.UTF8.GetBytes(reqStr);
  
  
              HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(a);
              request.Credentials = creds;
              request.Method = "SEARCH";
              request.ContentLength = reqBytes.Length;
              request.ContentType = "text/xml";
              request.Timeout = 300000;
              using (Stream requestStream = request.GetRequestStream())
              {
                  try
                  {
                      requestStream.Write(reqBytes, 0, reqBytes.Length);
                  }
                  catch
                  {
                  }
                  finally
                  {
                      requestStream.Close();
                  }
              }
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
              using (Stream responseStream = response.GetResponseStream())
              {
                  try
                  {
                      XmlDocument document = new XmlDocument();
                      document.Load(responseStream);
  
  
                      XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
                      nsmgr.AddNamespace("a", "DAV:");
                      nsmgr.AddNamespace("b", "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
                      nsmgr.AddNamespace("c", "xml:");
                      nsmgr.AddNamespace("d", "urn:schemas:mailheader:");
                      nsmgr.AddNamespace("e", "urn:schemas:httpmail:");
  
  
                      XmlNodeList responseNodes = document.GetElementsByTagName("a:response");
                      foreach (XmlNode responseNode in responseNodes)
                      {
  
                          XmlNode uriNode = responseNode.SelectSingleNode("child::a:href", nsmgr);
                          XmlNode propstatNode = responseNode.SelectSingleNode("descendant::a:propstat[a:status='HTTP/1.1 200 OK']", nsmgr);
                          if (propstatNode != null)
                          {
                              // read properties of this response, and load into a data object
                              XmlNode fromNode = propstatNode.SelectSingleNode("descendant::d:from", nsmgr);
                              XmlNode descNode = propstatNode.SelectSingleNode("descendant::e:textdescription", nsmgr);
                              XmlNode toNode = propstatNode.SelectSingleNode("descendant::d:to", nsmgr);
  
  
                              // make new data object
  
                              Mail mail = new Mail();
                              if (uriNode != null)
                                  mail.Uri = uriNode.InnerText;
                              if (fromNode != null)
                                  mail.From = fromNode.InnerText;
                              if (descNode != null)
                                  mail.Body = descNode.InnerText;
                              if (toNode != null)
                                  mail.To = toNode.InnerText;
                              unreadMail.Add(mail);
  
                          }
                      }
                      var ac = unreadMail;
  
                  }
                  catch (Exception e)
                  {
                      string msg = e.Message;
                  }
                  finally
                  {
  
                      responseStream.Close();
                  }
              }
  </code></pre>
  
  <p>in the output xml i get empty text description for undelivered emails:</p>
  
  <pre><code>&lt;a:status&gt;HTTP/1.1 404 Resource Not Found&lt;/a:status&gt;&lt;a:prop&gt;&lt;e:textdescription /&gt;&lt;/a:prop&gt;&lt;/a:propstat&gt;&lt;/a:response&gt;
  </code></pre>