I am trying to connect to iCloud via SmtpClient
The settings I use are as follows:
Server Name: smtp.mail.me.com
SSL Required: Yes If you see an error message when using SSL, try using TLS or STARTTLS instead.
Port: 587
SMTP authentication required: Yes - with the appropriate username and password
If I use SSL, I get the message "Handshake failed due to unexpected packet format"
If I do not use the SSL visual studio debugger, it hangs when I connect.
I think the problem is that I am not telling SmtpClient to use tls, but I cannot find documentation on how to do this.
The code is as follows:
using (var client = new SmtpClient()) { client.Timeout = 1000 * 20; //client.Capabilities. client.AuthenticationMechanisms.Remove ("XOAUTH2"); client.Connect("SMTP.mail.me.com", 587, false); //dies here //client.Connect(servername, port, useSsl); //can I set tls or starttls here?? client.Authenticate(username, password); client.Send(FormatOptions.Default, message); }
Is it possible to install TLS or StartTLS manually. One thing I tried is the following, but it doesn't seem to work.
client.Connect(new Uri("smtp://" + servername + ":" + port + "/?starttls=true"));
Thanks for any help with this.
source share