[英]Asp.Net Core MailKit: The remote certificate is invalid according to the validation proceedure
I have a question regarding email sending on asp.net core. 我有一个关于asp.net核心电子邮件发送的问题。
So I have this code: 所以我有这个代码:
private void SendEmailLocalSMTP(string email, string subject, string message)
{
MimeMessage mailMsg = new MimeMessage();
//TESTING ENVIRONMENT ONLY!!!
mailMsg.To.Add(new MailboxAddress("myMail@gmail.com", "cjimenezber@gmail.com"));
// From
mailMsg.From.Add(new MailboxAddress("noreply@app.com", "Facturacion"));
// Subject and multipart/alternative Body
mailMsg.Subject = subject;
string html = message;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("myMail@gmail.com", "myPassword");
// Init SmtpClient and send
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(credentials);
client.Send(mailMsg);
client.Disconnect(true);
}
}
From what I have found in other posts somewhat related, this should be enough to send it using MailKit, however it's not working properly. 从我在其他帖子中发现的有些相关,这应该足以使用MailKit发送它,但它不能正常工作。 I am getting the following exception and I don't know how to proceed from here. 我收到以下异常,我不知道如何从这里开始。
This is the exception: 这是例外:
I've seen this question, but I haven't made much sense from it: How to send email by using MailKit? 我已经看到了这个问题,但我没有太多意义: 如何使用MailKit发送电子邮件?
Any help is highly appreciated, thanks. 任何帮助都非常感谢,谢谢。
The problem you are hitting is that your system does not trust the GMail SSL certificate. 您遇到的问题是您的系统不信任GMail SSL证书。
Most likely the reason for this is because the Google Root CA certificate has not been imported into your Root certificate store. 最有可能的原因是因为Google Root CA证书尚未导入您的根证书存储区。
There are two ways around this: 有两种方法:
client.ServerCertificateValidationCallback
通过在client.ServerCertificateValidationCallback
上设置自己的证书验证回调方法来覆盖证书验证 For more information, see the FAQ: https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate 有关更多信息,请参阅常见问题解答: https : //github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.