[英]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): 根据您所处环境的配置,可以在此处应用多种解决方案(有关更多信息,请参见此处 ):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.