Link to home
Start Free TrialLog in
Avatar of programmerist 1983
programmerist 1983Flag for Türkiye

asked on

How to use Microsoft.Exchange.WebServices ?

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

Error return line:service.AutodiscoverUrl("myusernamek@xxxx.com");

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("myusernamek@xxxx.com", "mypassword", "xxxx.com");
                service.TraceEnabled = true;
                service.AutodiscoverUrl("myusernamek@xxxx.com");

                // Create the e-mail message, set its properties, and send it to user2@contoso.com, 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("rcipientnamei@xxxx.aero");
                message.SendAndSaveCopy();

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

        }
    }
}

Open in new window

Avatar of JuusoConnecta
JuusoConnecta
Flag of Sweden image

What are you trying to accomplish ?
ASKER CERTIFIED SOLUTION
Avatar of Dennis Aries
Dennis Aries
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial