C # programmatically read emails from an Exchange server

When you search the Internet, you will find very simple answers for “How to read emails programmatically” ... The websites explain most of the same as on this page. 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); } 

it fails when it runs the autodiscoverURL line. The error says: "Could not find the Autodiscover service."

So, I wentogled on and found this site from Microsoft https://www.testexchangeconnectivity.com/#&&/wEXAQUBcwUBME93h2+JjI0+MV2gTqcRL0g43z9m Here you can test my mail server .... When I pass the parameters, I get an error below. ...

But I still do not understand what is the problem? Do I need to add a record in DNS? Can anyone help?

 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 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 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 
+8
c # exchange-server exchange-server-2007
source share
4 answers

You do not need to use autodiscover if you already know the address of your exchange server. Try it instead (for more information see here :

 service.Url = new Uri("https://hostname/EWS/Exchange.asmx"); 

Replace "hostname" with the hostname for your exchange server.

+15
source share

Hope you should have a solution by this time. It just helps someone stumble upon this post. I found a solution on one of the article on technology , I’m cheating to sew me, and it works fine for me.

Just replace the line in the code as follows:

 service.AutodiscoverUrl("user@yourdomain.com", delegate { return true; }); 

I had some other problems, but not related to this bit.

Happy coding,

Sanjay.

+2
source share

I had the same problem with AutoDiscover. This is not necessary, you can specify your URL, for example

  Uri myUri = new Uri("https://Hostname/ews/exchange.asmx"); userData.AutodiscoverUrl = myUri; service.Url = myUri; 

As the host name, you can put the IP address of the server, such as 192.168.100.10

Alternatively, to find out what hostname of your Exchange server (the entire URL is actually used), if you use Outlook, go to the computer’s launchpad where the date and time are displayed, you will find the Outlook icon, hold Ctrl + right click on perspective icon and click on "Verify Email Configuration"

Check the box next to "Use auto detection." Enter the email address hosted on this Exchange server, along with its password, and you will get a bunch of URLs. Use 1 that says "accessibility service URL"

+1
source share

Note that the transmitted credentials must have permission for this exchange mailbox / server. In my case, using a different set of credentials that are correctly resolved works, but not for the service account I'm trying to work with. As soon as I find out what exactly is needed for the account, I will update it here.

Update. My problem was that the service account was from a domain other than the domain on which the instance of Exchange 2007 is running, even though there is a trust relationship between them. I found this to be an issue registered in Exchange 2007 related to the way she views accounts in her forest. As a result, I had to create an identical service account (name / password) in the domain on which the exchange server is sitting, and specify the username as {exchange_domain} {service_account_name}. The Windows service that calls EWS works as {original_domain} {service_account_name}.

For reference, the exception was: Microsoft.Exchange.WebServices.Data.ServiceResponseException: Failed to get valid Active Directory information for the calling account. Verify that this is a valid Active Directory account.

0
source share

All Articles