Connecting to smtp.live.com with the TcpClient class
I'm trying to connect to smtp.live.com using the TcpClient class.  There is a wonderful example of connecting to Gmail here: http://stackoverflow.com/questions/1633391/testing-smtp-server-is-running-via-c

Unfortunately, when updating this to work with smtp.live.com, I'm getting an "IOException: The handshake failed due to an unexpected packet format" when the AuthenticateAsClient method is called.

How can I work around this?


    class Program
    {
        static void Main(string[] args)
        {
            using (var client = new TcpClient())
            {
                var server = "smtp.live.com";
                var port = 25;
                client.Connect(server, port);
                using (var stream = client.GetStream())
                using (var sslStream = new SslStream(stream))
                {
                    // Getting an IOException here
                    sslStream.AuthenticateAsClient(server);
                    using (var writer = new StreamWriter(sslStream))
                    using (var reader = new StreamReader(sslStream))
                    {
                        writer.WriteLine("EHLO " + server);
                        writer.Flush();
                        Console.WriteLine(reader.ReadLine());
                    }
                }
            }
            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }
    }

I tried specifying the SslProtocol in AuthenticateAsClient.  Neither Tls or Ssl3 worked.

Also tried providing a callback for RemoteCertificateValidation that alway returned true just in case the server cert was invalid.  That didn't work either.

NOTE: Please do not suggest that I use SmtpClient; I need more control than it provides.
Connecting to smtp.live.com with the TcpClient class
===

I'm trying to connect to smtp.live.com using the TcpClient class.  There is a wonderful example of connecting to Gmail here: http://stackoverflow.com/questions/1633391/testing-smtp-server-is-running-via-c

Unfortunately, when updating this to work with smtp.live.com, I'm getting an "IOException: The handshake failed due to an unexpected packet format" when the AuthenticateAsClient method is called.

How can I work around this?


    class Program
    {
        static void Main(string[] args)
        {
            using (var client = new TcpClient())
            {
                var server = "smtp.live.com";
                var port = 25;
                client.Connect(server, port);
                using (var stream = client.GetStream())
                using (var sslStream = new SslStream(stream))
                {
                    // Getting an IOException here
                    sslStream.AuthenticateAsClient(server);
                    using (var writer = new StreamWriter(sslStream))
                    using (var reader = new StreamReader(sslStream))
                    {
                        writer.WriteLine("EHLO " + server);
                        writer.Flush();
                        Console.WriteLine(reader.ReadLine());
                    }
                }
            }
            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }
    }

I tried specifying the SslProtocol in AuthenticateAsClient.  Neither Tls or Ssl3 worked.

Also tried providing a callback for RemoteCertificateValidation that alway returned true just in case the server cert was invalid.  That didn't work either.

NOTE: Please do not suggest that I use SmtpClient; I need more control than it provides.