我試圖通過SmtpClient連接到iCloudMailkit SMTP - 啓動TLS和TLS標誌
我使用的設置如下:
服務器名稱:smtp.mail.me.com
要求SSL :是
如果您在使用SSL時看到錯誤消息,請嘗試使用TLS或STARTTLS。
端口:587
SMTP需要身份驗證:是 - 與相關用戶名和密碼
如果我使用SSL我得到「握手失敗,原因是意外的數據包格式」
如果我不使用SSL視覺工作室調試器掛在連接上。
我認爲問題是我不告訴SmtpClient使用tls,但我無法找到如何做到這一點的文檔。
的代碼如下:
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);
}
我能夠手動設置TLS或啓動TLS。我嘗試過的一件事是以下,但它似乎並沒有工作
client.Connect(new Uri("smtp://" + servername + ":" + port + "/?starttls=true"));
感謝您的任何幫助。
如果你說你需要'SSL',你爲什麼要爲'useSSL'標誌傳遞'false'? – Rob
@Rob我已經嘗試使用true,並且由於意外的數據包格式而導致握手失敗。 iCloud建議:「如果您在使用SSL時看到錯誤消息,請嘗試使用TLS或STARTTLS。」 – cavej03