views:

51

answers:

1

i try to use : Microsoft.Exchange.WebServices.dll to use outlook. but connection return error

Error return line:service.AutodiscoverUrl("[email protected]");

The Autodiscover service could not be located. my codes:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Autodiscover;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Connect to Exchange Web Services as user1 at contoso.com.
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials("[email protected]", "mypassword", "xxxx.com");
                service.TraceEnabled = true;
                service.AutodiscoverUrl("[email protected]");

                // Create the e-mail message, set its properties, and send it to [email protected], saving a copy to the Sent Items folder. 
                EmailMessage message = new EmailMessage(service);
                message.Subject = "Interesting";
                message.Body = "The proposition has been considered.";
                message.ToRecipients.Add("[email protected]");
                message.SendAndSaveCopy();

                // Write confirmation message to console window.
                Console.WriteLine("Message sent!");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.ReadLine();
            }

        }
    }
}

alt text

A: 

The code suggest that you have an Exchange 2007 server... Is it properly configured for using the Autodiscover features? Confirm that you can ping autodiscover.XXXX.com and view https://autodiscover.XXXX.com in a web browser.

Alternately, you may need to use your internal domain name for autodiscovery and login. For example, in my office the external email addresses are on a domain like CompanyX.com, but the internal Active Directory domain is like CompanyX.local, and we do not have autodiscover on the open Internet, so my EWS needs to locate Autodiscover.CompanyX.local.

ewall
ok. How can i solve it? i need yor help:)
Phsika