![](/img/trans.png)
[英]Cannot send Email :( - The remote certificate is invalid according to the validation procedure
[英]ASP.Net MVC 5 Sending Email error: The remote certificate is invalid according to the validation procedure
发送电子邮件时,我有一个ASP.Net MVC 5应用程序出现以下错误:
根据验证过程,远程证书无效。
说明:执行当前Web请求期间发生未处理的异常。 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
异常详细信息:System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。
源错误:
当前Web请求的执行期间生成了未处理的异常。 可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。
堆栈跟踪:
[AuthenticationException:根据验证过程,远程证书无效。]
System.Net.Mail.ConnectAndHandshakeAsyncResult.End(IAsyncResult结果)+113 System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult结果)+61[SmtpException:发送邮件失败。]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+144
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(任务任务)+144 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+84
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+143
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。<> 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.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.MvcHandler.b__5(IAsyncResult asyncResult,ProcessRequestState innerState)+51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+111
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)+195
我发送电子邮件的代码:
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");
}
您在此处看到的问题与用于远程电子邮件环境提供的SMTP服务的SSL证书有关。
要检查SSL证书,您可以通过以下方式使用openSSL:
openssl s_client -connect exchange01.int.contoso.com:25 -starttls smtp
根据您所处环境的配置,可以在此处应用多种解决方案(有关更多信息,请参见此处 ):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.