Tec*_*Guy 2 c# smtp winforms mailkit
我对在使用 MailKit 设置 smtp 时如何使用第三个参数感到困惑。
这是我到目前为止所拥有的:
// *************** SEND EMAIL *******************
using (var client = new MailKit.Net.Smtp.SmtpClient(new ProtocolLogger("smtp.log")))
{
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
//accept all SSL certificates
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// client.Connect(emailSettings.SmtpServer, emailSettings.SmtpPort, emailSettings.IsSslEnabled);
client.Connect(emailSettings.SmtpServer, emailSettings.SmtpPort, emailSettings.AuthType);
if (emailSettings.IsAuthenticationRequired)
{
// Note: only needed if the SMTP server requires authentication
client.Authenticate(emailSettings.SmtpUsername, emailSettings.SmtpPassword);
}
if (emailSettings.TimeOut == 0) emailSettings.TimeOut = 10;
client.Timeout = emailSettings.TimeOut * 1000;
client.Send(message);
client.Disconnect(true);
}
Run Code Online (Sandbox Code Playgroud)
我的困惑在于这一行:
client.Connect(emailSettings.SmtpServer, emailSettings.SmtpPort , true);
Run Code Online (Sandbox Code Playgroud)
我可以选择传递 true/false 或 SecureSockOptions。
这就是我的表格上的内容:
我不确定我是否理解这两种不同的设置如何影响电子邮件的发送。我假设我使用 useSsl 的 true/false 或 SecureSockOptions?我不确定这些是如何协同工作的。
SecureSockOptions 的选项有:
无 自动 SslOnConnect StartTls StartTlsWhenAvailable
这些选项是否不需要 useSsl?
useSsl是 的简化版本SecureSocketOptions。
当您传递truefor时useSsl,它会映射到SecureSocketOptions.SslOnConnect.
当您传递falsefor时useSsl,它会映射到SecureSocketOptions.StartTlsWhenAvailable.