简体   繁体   English

Asp.Net Core MailKit:根据验证过程,远程证书无效

[英]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: 有两种方法:

  1. Import Google's Root CA certificate into your system (how to do this varies depending on Windows, Linux, MacOS) 将Google的根CA证书导入您的系统(如何执行此操作因Windows,Linux,MacOS而异)
  2. Override the certificate validation by setting your own certificate validation callback method on 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.

相关问题 .Net Core + Kubernetes > AuthenticationException:远程证书根据验证程序无效 - .Net Core + Kubernettes > AuthenticationException: The remote certificate is invalid according to the validation procedure ASP.Net MVC 5发送电子邮件错误:根据验证过程,远程证书无效 - ASP.Net MVC 5 Sending Email error: The remote certificate is invalid according to the validation procedure ASP.Net Core 3 远程证书在 MacOs 上无效 - ASP.Net Core 3 The remote certificate is invalid on MacOs MailKit C#ImapClient.Connect()到Office 365的生成异常:“根据验证过程,远程证书无效” - MailKit C# ImapClient.Connect() to Office 365 generating exception: “The remote certificate is invalid according to the validation procedure” .NET C# “根据验证程序,远程证书无效” - .NET C# "The remote certificate is invalid according to the validation procedure" MailKit C# SmtpClient.Connect() 到 smtp.Office365.com 抛出异常:“根据验证程序,远程证书无效。” - MailKit C# SmtpClient.Connect() to smtp.Office365.com throwing exception: "The remote certificate is invalid according to the validation procedure." ASP.NET Core远程验证未显示 - ASP.NET Core Remote Validation not showing “根据验证程序,远程证书无效” wcf - “The remote certificate is invalid according to the validation procedure” wcf FluentFTP:根据验证程序远程证书无效 - FluentFTP: The remote certificate is invalid according to the validation procedure AuthenticateAsServer - 根据验证过程,远程证书无效 - AuthenticateAsServer - The remote certificate is invalid according to the validation procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM