-1

I want to read/connect other user inbox mail(office outloook 2010) from my pc using user credentials. But I am getting below error.

The Autodiscover service couldn't be located

plz give me a solution.

    public void ConnectToExchangeServer()
    {
        ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        try
        {
            exchange.TraceEnabled = true;
            exchange.Credentials = new WebCredentials("xyz", "xyz", "xyz.in");  
            exchange.AutodiscoverUrl("xyz@xyz.com", RedirectionUrlValidationCallback);
            exchange.Url `enter code here`= new Uri("https://usercomputername.domainname");

            EnableFolderPermissions(exchange);                
        }
        catch (Exception ex)
        {

        }
    }
  • Are you sure your `exchange.Url` points to the correct URL, i.e. the address of your EWS managed API? `"The autodiscover field (in your exchange server settings) needs to be populated with an address that ends with: "EWS/Exchange.asmx"."` See also: https://support.practicepanther.com/calendar-and-events/troubleshooting/how-do-i-fix-the-autodiscover-service-couldnt-be-located-error and https://stackoverflow.com/questions/15065363/autodiscover-service-couldnt-be-located-when-trying-to-access-exchange-2010-a – LocEngineer Nov 30 '18 at 14:34
  • Does autodiscover work if you (as a test) use the credentials of the mailbox owner? – Dmitry Streblechenko Nov 30 '18 at 14:48
  • Hi there, basically when I am trying to debug on that 'exchange.AutodiscoverUrl' then 'The Autodiscover service couldn't be located' error arise. I am using mailbox owner username, password and DomainName. and also using exchange.Url = new Uri("https://userCompName.userDomainName/EWS/Exchange.asmx") – Soumyadeep.R Dec 03 '18 at 06:29
  • Are you perhaps trying this from outside the domain network? – LocEngineer Dec 03 '18 at 10:02

1 Answers1

0

How to read only unread mails from specific inbox folder using 'MailServer'?

Here my code:

        if (!Directory.Exists(mailbox))
        {
            Directory.CreateDirectory(mailbox);
        }
        MailServer oServer = new MailServer("servername",
                    "username", "password", ServerProtocol.Imap4);
        MailClient oClient = new MailClient("TryIt");
        oServer.SSLConnection = true;
        oServer.Port = 143;     
        try
        {
            oClient.Connect(oServer);
            MailInfo[] infos = oClient.GetMailInfos();
            for (int i = 0; i < infos.Length; i++)
            {
                MailInfo info = infos[i];
                Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}; Flags: {3}",
                    info.Index, info.Size, info.UIDL, info.Flags);

                // Receive email from POP3 server
                Mail oMail = oClient.GetMail(info);

                Console.WriteLine("From: {0}", oMail.From.ToString());
                Console.WriteLine("To: {0}", oMail.To.ToString());
                Console.WriteLine("Subject: {0}\r\n", oMail.Subject);
                if (oMail.Attachments.Length > 0)
                {
                    for (int j = 0; j <= oMail.Attachments.Length - 1; j++)
                        {
                            System.DateTime d = System.DateTime.Now;
                            System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US");
                            string sdate = d.ToString("MMddyyyyHHmmss", cur);
                            string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i);

                            // Save email to local disk
                            oMail.SaveAs(fileName, true);



                            // Mark email as deleted from POP3 server.
                            oClient.Delete(info);
                        }
                    }
            }
            // Quit and purge emails marked as deleted from POP3 server.
            oClient.Quit();
        }
        catch (Exception ep)
        {
            Console.WriteLine(ep.Message);
        }