【发布时间】:2019-11-28 13:44:24
【问题描述】:
在使用 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);
}
我的困惑在于这一行:
client.Connect(emailSettings.SmtpServer, emailSettings.SmtpPort , true);
我可以选择传入 true/false 或 SecureSockOptions。
这是我的表单上的内容:
我不确定我是否了解这两种不同的设置如何影响电子邮件的发送。我假设我对 useSsl 或 SecureSockOptions 使用真/假?我不确定这些是如何协同工作的。
SecureSockOptions 的选项有:
无自动 SslOnConnect StartTls StartTlsWhenAvailable
这些选项是否否定了对 useSsl 的需求?
【问题讨论】: