简体   繁体   English

ASP.Net MVC 5发送电子邮件错误:根据验证过程,远程证书无效

[英]ASP.Net MVC 5 Sending Email error: The remote certificate is invalid according to the validation procedure

I have an ASP.Net MVC 5 application when I send email get bellow error: 发送电子邮件时,我有一个ASP.Net MVC 5应用程序出现以下错误:

The remote certificate is invalid according to the validation procedure. 根据验证过程,远程证书无效。

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

Exception Details: System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. 异常详细信息:System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。

Source Error: 源错误:

An unhandled exception was generated during the execution of the current web request. 当前Web请求的执行期间生成了未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below. 可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。

Stack Trace: 堆栈跟踪:

[AuthenticationException: The remote certificate is invalid according to the validation procedure.] [AuthenticationException:根据验证过程,远程证书无效。]
System.Net.Mail.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) +113 System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result) +61 System.Net.Mail.ConnectAndHandshakeAsyncResult.End(IAsyncResult结果)+113 System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult结果)+61

[SmtpException: Failure sending mail.] [SmtpException:发送邮件失败。]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84 VRM5.Controllers.d__5.MoveNext() in C:\\Users\\mehdi\\Documents\\Visual Studio 2015\\Projects\\VRM5\\VRM5\\Controllers\\VRsController.cs:289 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+84 VRM5.Controllers.d__5.MoveNext()在C:\\ Users \\ mehdi \\ Documents \\ Visual Studio 2015 \\ Projects \\ VRM5 \\ VRM5 \\ Controllers \\ VRsController.cs: 289
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+144 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+84
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +143 System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+143
System.Web.Mvc.Async.<>c__DisplayClass37.b__36(IAsyncResult asyncResult) +23 System.Web.Mvc.Async。<> c__DisplayClass37.b__36(IAsyncResult asyncResult)+23
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +112 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +452 System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+112 System.Web.Mvc.Async。<> c__DisplayClass46.b__3f()+452 System.Web.Mvc.Async。<> c__DisplayClass33.b__32(IAsyncResult asyncResult)+ 15
System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +37 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +241 System.Web.Mvc.Async。<> c__DisplayClass2b.b__1c()+37 System.Web.Mvc.Async。<> c__DisplayClass21.b__1e(IAsyncResult asyncResult)+241
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29 System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult,ExecuteCoreState innerState)+29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+53 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+19
System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51 System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult,ProcessRequestState innerState)+51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+111
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +195 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)+195

my code for sending email: 我发送电子邮件的代码:

var message = new MailMessage();
//-----Send Email------------------------------------------//
message.To.Add(new MailAddress(Q_contacts.ContactEmail));  // replace with valid value 
if(CheckAD==1)
{
    message.CC.Add(new MailAddress( mehdi@hotmail.com"));
}

message.From = new MailAddress(vR.Email);  // replace with valid value
message.Subject = "Vehicle Request -"+vR.Distination;
//message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
message.Body = MS_1;
message.IsBodyHtml = true;

using (var smtp = new SmtpClient())
{
    var credential = new NetworkCredential
    {
        UserName = "mehdi@abc.org",  // replace with valid value
        Password = "Abc@abc123"  // replace with valid value
    };
    smtp.Credentials = credential;
    smtp.Host = "mr09.hv.abc.org";
    smtp.Port = 25;
    smtp.EnableSsl = false;
    await smtp.SendMailAsync(message);
    return RedirectToAction("Index");
}

The issue you see here is related to the SSL certificate used for the SMTP service offered by the remote email environment. 您在此处看到的问题与用于远程电子邮件环境提供的SMTP服务的SSL证书有关。

To check the SSL certificate you can use openSSL via: 要检查SSL证书,您可以通过以下方式使用openSSL:

openssl s_client -connect exchange01.int.contoso.com:25 -starttls smtp openssl s_client -connect exchange01.int.contoso.com:25 -starttls smtp

Depending on the configuration in your situation multiple solutions might apply here (see here for more infos): 根据您所处环境的配置,可以在此处应用多种解决方案(有关更多信息,请参见此处 ):

  • The hostname isn´t in the SSL certificate. 主机名不在SSL证书中。 Then the remote mail server must be reconfigured. 然后,必须重新配置远程邮件服务器。
  • The remote mail server still used an self signed certificate. 远程邮件服务器仍使用自签名证书。 You can try to import that on your server (see link above). 您可以尝试将其导入服务器中(请参见上面的链接)。
  • Some SSL certificates used here are outdated. 这里使用的某些SSL证书已过时。 Then the remote mail server must be reconfigured. 然后,必须重新配置远程邮件服务器。
  • Some parts from the certification chain aren´t trusted. 认证链中的某些部分不受信任。 To solve the issue you need to import them into the trusted SSL store on your server (see link above). 要解决此问题,您需要将它们导入服务器上受信任的SSL存储中(请参见上面的链接)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法发送电子邮件:(--根据验证步骤,远程证书无效 - Cannot send Email :( - The remote certificate is invalid according to the validation procedure .NET C# “根据验证程序,远程证书无效” - .NET C# "The remote certificate is invalid according to the validation procedure" .Net Core + Kubernetes &gt; AuthenticationException:远程证书根据验证程序无效 - .Net Core + Kubernettes > AuthenticationException: The remote certificate is invalid according to the validation procedure 获取令牌时出错“根据验证过程,远程证书无效” - Error when get token “The remote certificate is invalid according to the validation procedure” Asp.Net Core MailKit:根据验证过程,远程证书无效 - Asp.Net Core MailKit: The remote certificate is invalid according to the validation proceedure “根据验证程序,远程证书无效” wcf - “The remote certificate is invalid according to the validation procedure” wcf AuthenticateAsServer - 根据验证过程,远程证书无效 - AuthenticateAsServer - The remote certificate is invalid according to the validation procedure FluentFTP:根据验证程序远程证书无效 - FluentFTP: The remote certificate is invalid according to the validation procedure SSL证书问题 - 根据验证程序,远程证书无效 - SSL Certificate Issue - The remote certificate is invalid according to the validation procedure 根据使用自签名证书的验证程序,远程证书无效 - The remote certificate is invalid according to the validation procedure with self-signed certificate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM