ASP.NET Core + Amazon SES:根据验证程序,远程证书无效

ASP.NET Core + Amazon SES: The remote certificate is invalid according to the validation procedure

我正在尝试使用 ASP.NET Core、MailKit 和 Amazon SES 发送电子邮件:

  using (SmtpClient client = new SmtpClient(new ProtocolLogger("smtp.log"))) {
      client.Connect("email-smtp.us-east-1.amazonaws.com", 587, SecureSocketOptions.StartTls);
      client.Authenticate("myusername", "mypassword");
      await client.SendAsync(message);
      client.Disconnect(true);
  }

我一直收到错误 "The remote certificate is invalid according to the validation procedure."。

并且日志文件显示:

Connected to smtp://email-smtp.us-east-1.amazonaws.com:587/?starttls=always
S: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-1737464811 qt5bXhIgVseJaHPspjp4
C: EHLO [127.0.0.1]
S: 250-email-smtp.amazonaws.com
S: 250-8BITMIME
S: 250-SIZE 10485760
S: 250-STARTTLS
S: 250-AUTH PLAIN LOGIN
S: 250 Ok
C: STARTTLS
S: 220 Ready to start TLS

我错过了什么?

您需要提供自己的client.ServerCertificateValidationCallback方法来验证服务器证书。它可以像总是返回 true 一样简单,也可以根据服务器的已知指纹或任何其他可能性检查指纹。

有关详细信息,请参阅 http://www.mimekit.org/docs/html/P_MailKit_MailService_ServerCertificateValidationCallback.htm