c# - Mailkit SMTP - StartTLS & TLS flags -
i trying connect icloud via smtpclient
the settings using follows:
server name: smtp.mail.me.com
ssl required: yes
if see error message when using ssl, try using tls or starttls instead.
port: 587
smtp authentication required: yes - relevant username , password
if use ssl "handshake failed due unexpected packet format"
if don't use ssl visual studio debugger hangs on connect.
i think problem not telling smtpclient use tls cant find documentation on how this.
the code 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 set tls or starttls here?? client.authenticate(username, password); client.send(formatoptions.default, message); } am able set tls or starttls manually. 1 thing did try following did not seem work
client.connect(new uri("smtp://" + servername + ":" + port + "/?starttls=true")); thanks this.
the connect() method using allows enabling/disabling ssl-wrapped connections not same thing starttls.
due confusion, i've implemented separate connect() method makes more obvious going on:
using (var client = new smtpclient()) { // note: don't set timeout unless know doing. //client.timeout = 1000 * 20; // removing here won't because authenticationmechanisms // not populated until client connects server. //client.authenticationmechanisms.remove ("xoauth2"); client.connect ("smtp.mail.me.com", 587, securesocketoptions.starttls); client.authenticationmechanisms.remove ("xoauth2"); client.authenticate (username, password); client.send (message); } try that.
Comments
Post a Comment