c#以编程方式从Exchange服务器读取电子邮件

当您在网上搜索时,您会找到“如何以编程方式阅读电子邮件”的简单答案...... Al网站正在解释大部分相同的内容,例如此页面。 http://omegacoder.com/?p=454
// depends from Exchange server version      
        service.Credentials = new NetworkCredential("MDR", "password", "zzz");
        service.AutodiscoverUrl("mdr@zzz.be");
        object o = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        foreach (Item item in findResults.Items)
        {
            Console.WriteLine(item.Subject);
        }
它在执行autodiscoverURL行时失败。错误显示“无法找到自动发现服务”。 所以我进一步搜索并从微软https://www.testexchangeconnectivity.com/#&&/wEXAQUBcwUBME93h2+JjI0+MV2gTqcRL0g43z9m找到了这个网站。在这里你可以测试你的邮件服务器.... 当我传递参数时,我得到以下错误.... 但我还是不明白问题是什么?我是否需要向DNS添加记录?有人可以帮忙吗?
Attempting to test potential Autodiscover URL https://autodiscover.zzz.be/AutoDiscover/AutoDiscover.xml
 Testing of this potential Autodiscover URL failed.
 Test Steps
 Attempting to resolve the host name autodiscover.ncb.be in DNS.
 The host name resolved successfully.
 Additional Details
 IP addresses returned: 213.246.192.205

Testing TCP port 443 on host autodiscover.ncb.be to ensure it's listening and open.
 The specified port is either blocked, not listening, or not producing the expected response.
  Tell me more about this issue and how to resolve it
 Additional Details
 A network error occurred while communicating with the remote host.
Exception details:
Message: No connection could be made because the target machine actively refused it 213.246.192.205:443
Type: System.Net.Sockets.SocketException
Stack trace:
at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port)
at Microsoft.Exchange.Tools.ExRca.Tests.TcpPortTest.PerformTestReally()




Attempting to contact the Autodiscover service using the HTTP redirect method.
 The attempt to contact Autodiscover using the HTTP Redirect method failed.
 Test Steps
 Attempting to resolve the host name autodiscover.zzz.be in DNS.
 The host name resolved successfully.
 Additional Details
 IP addresses returned: 213.246.192.205

Testing TCP port 80 on host autodiscover.zzz.be to ensure it's listening and open.
 The port was opened successfully.
ExRCA is checking the host autodiscover.zzz.be for an HTTP redirect to the Autodiscover service.
 ExRCA failed to get an HTTP redirect response for Autodiscover.
 Additional Details
 A Web exception occurred because an HTTP 404 - NotFound response was received from IIS7.



Attempting to contact the Autodiscover service using the DNS SRV redirect method.
 ExRCA failed to contact the Autodiscover service using the DNS SRV redirect method.
 Test Steps
 Attempting to locate SRV record _autodiscover._tcp.ncb.be in DNS.
 The Autodiscover SRV record wasn't found in DNS.
  Tell me more about this issue and how to resolve it
    
已邀请:
如果您已经知道Exchange服务器的地址,则不一定需要使用自动发现。请尝试以下方法(有关详细信息,请查看此处:
service.Url = new Uri("https://hostname/EWS/Exchange.asmx");
将“hostname”替换为Exchange服务器的主机名。     
我希望你现在应该有解决方案了。这只是为了帮助任何人碰到这篇文章。  我找到了一篇关于technet文章的解决方案,我试图解决这个问题,并为我工作正常。 只需用以下内容替换代码中的行:
service.AutodiscoverUrl("user@yourdomain.com",
delegate
{
     return true;
});
我有一些其他问题,但与这一点无关。 快乐的编码, 桑杰。     
我在AutoDiscover中遇到了同样的问题。没有必要,您可以指定您的URL
    Uri myUri = new Uri("https://Hostname/ews/exchange.asmx");
    userData.AutodiscoverUrl = myUri;
    service.Url = myUri;
作为主机名,您可以将服务器IP地址设置为192.168.100.10 或者,要查找您的Exchange服务器主机名(实际上是要使用的整个URL),如果您使用的是Outlook,请转到计算机启动栏,其中显示日期和时间,您将找到Outlook图标,按住Ctrl键+右键单击Outlook图标,然后单击“测试电子邮件自动配置” 选中“使用自动发现”复选框。输入该Exchange Server上托管的电子邮件地址及其密码,您将收到一堆网址。使用显示“可用性服务URL”的1     
请考虑传递的凭据需要具有给定交换邮箱/服务器的权限。在我的情况下,使用正确许可的一组不同的凭据可以工作,但不能用于我正在努力工作的服务帐户。 一旦我发现该帐户需要获得哪些权限,我将在此处进行更新。 更新:我的问题是服务帐户来自与运行Exchange 2007实例的域不同的域,即使两者之间存在信任关系。我发现这是Exchange 2007中有关如何在其林中查找帐户的已记录的已知问题。最后,必须在交换服务器所在的域上创建相同的服务帐户(名称/通行证),并将用户名指定为{exchange_domain} {service_account_name}。调用EWS的Windows服务以{original_domain} {service_account_name}运行。 作为参考,例外是: Microsoft.Exchange.WebServices.Data.ServiceResponseException: 无法获得呼叫帐户的有效Active Directory信息。确认它是有效的Active Directory帐户。     

要回复问题请先登录注册