简体   繁体   English

以编程方式从Exchange Server 2010邮箱中读取电子邮件

[英]Programmatically reading emails from Exchange Server 2010 mailbox

we have ac# application that reads an email Inbox currently hosted on Exchange 2003 using the http service. 我们有一个ac#应用程序,该应用程序使用http服务读取Exchange 2003上当前托管的电子邮件收件箱。

Now the mailbox is to be migrated to an Exchange 2010 server, so we are testing our code to confirm it will still work. 现在,该邮箱将被迁移到Exchange 2010服务器,因此我们正在测试我们的代码以确认它仍然可以工作。

We are getting an error 'Bad request' with the below code (which tries to get all the mail): public static XmlDocument GetUnreadMailAll() { HttpWebRequest loRequest = default(HttpWebRequest); 使用以下代码(试图获取所有邮件),我们收到错误“错误请求”:public static XmlDocument GetUnreadMailAll(){HttpWebRequest loRequest = default(HttpWebRequest); HttpWebResponse loResponse = default(HttpWebResponse); HttpWebResponse loResponse =默认值(HttpWebResponse); string lsRootUri = null; 字符串lsRootUri = null; string lsQuery = null; 字符串lsQuery = null; byte[] laBytes = null; byte [] laBytes = null;

        Stream loRequestStream = default(Stream);
        Stream loResponseStream = default(Stream);
        XmlDocument loXmlDoc = default(XmlDocument);
        loXmlDoc = new XmlDocument();
        try
        {
            lsRootUri = strServer + "/Exchange/" + strAlias + "/" + strInboxURL;
            lsQuery = "<?xml version=\"1.0\"?>"
                + "<D:searchrequest xmlns:D = \"DAV:\" xmlns:m=\"urn:schemas:httpmail:\">"
                + "<D:sql>SELECT "
                + "\"urn:schemas:httpmail:to\", "
                + "\"urn:schemas:httpmail:displayto\", "
                + "\"urn:schemas:httpmail:from\", "
                + "\"urn:schemas:httpmail:fromemail\", "
                + "\"urn:schemas:httpmail:subject\", "
                + "\"urn:schemas:httpmail:textdescription\", "
                //+ "\"urn:schemas:httpmail:htmldescription\", "
                + "\"urn:schemas:httpmail:hasattachment\", "
                + "\"urn:schemas:httpmail:attachmentfilename\", "
                + "\"urn:schemas:httpmail:senderemail\", "
                + "\"urn:schemas:httpmail:sendername\", "
                + "\"DAV:displayname\", "
                + "\"urn:schemas:httpmail:datereceived\", "
                + "\"urn:schemas:httpmail:read\", "
                + "\"DAV:id\" "
                + "FROM \"" + lsRootUri
                + "\" WHERE \"DAV:ishidden\" = false "
                + "AND \"DAV:isfolder\" = false "
                + "AND \"urn:schemas:httpmail:read\" = false "
                + "AND \"urn:schemas:httpmail:fromemail\" != 'emailAddy@domainName.co.uk' "
                + "</D:sql></D:searchrequest>";
            loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
            loRequest.Credentials = new NetworkCredential(strUserName, 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();
        }

the exception is thrown on the line loResponseStream = loResponse.GetResponseStream(); 在行loResponseStream = loResponse.GetResponseStream();上引发了异常loResponseStream = loResponse.GetResponseStream();

here is the xml that we are sending: 这是我们要发送的xml:

  <?xml version="1.0" ?> 
- <D:searchrequest xmlns:D="DAV:" xmlns:m="urn:schemas:httpmail:">
  <D:sql>SELECT "urn:schemas:httpmail:to", "urn:schemas:httpmail:displayto", "urn:schemas:httpmail:from", "urn:schemas:httpmail:fromemail", "urn:schemas:httpmail:subject", "urn:schemas:httpmail:textdescription", "urn:schemas:httpmail:hasattachment", "urn:schemas:httpmail:attachmentfilename", "urn:schemas:httpmail:senderemail", "urn:schemas:httpmail:sendername", "DAV:displayname", "urn:schemas:httpmail:datereceived", "urn:schemas:httpmail:read", "DAV:id" FROM "https://domain/Exchange/bbtest/Inbox" WHERE "DAV:ishidden" = false AND "DAV:isfolder" = false AND "urn:schemas:httpmail:read" = false AND "urn:schemas:httpmail:fromemail" != 'emailAddy@domainName.co.uk'</D:sql> 
  </D:searchrequest>

and from MSDN the answer is that WebDAV is deprecated after Exchange 2007 , and replaced by Exchange Web Services 从MSDN得到的答案是, 在Exchange 2007之后不赞成使用WebDAV ,而由Exchange Web Services代替

here are a couple of links: 这里有几个链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c#以编程方式从Exchange服务器读取电子邮件 - c# programmatically reading emails from the Exchange server 启用Exchange 2010邮箱 - Enable exchange 2010 mailbox C# 如何从 C# 控制台应用程序以编程方式访问共享 Outlook/Exchange 邮箱以将电子邮件从收件箱移动到另一个文件夹 - C# How to access a shared outlook/exchange mailbox programmatically from a C# console application to move emails from inbox to another folder 如何以编程方式从C#Web应用程序在Exchange 2007服务器上添加邮箱别名? - How to programmatically add mailbox alias on an Exchange 2007 server from C# web app? 订阅在Exchange Server 2010中创建新邮箱时引发的事件 - Subscribing to the event raised when a new mailbox is created in Exchange Server 2010 阅读来自Exchange服务器的电子邮件 - Read emails from Exchange server C#从MS Exchange阅读电子邮件 - C# reading Emails from MS Exchange 使用 C# 从 Office 365 邮箱读取电子邮件 - Reading Emails from Office 365 mailbox using C# 删除EWS ExchangeVersion.Exchange2013与2010中的电子邮件 - Delete emails from EWS ExchangeVersion.Exchange2013 vs 2010 使用C#将电子邮件从imap迁移到Exchange 2010 - migrating emails from imap to exchange 2010 using c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM