【发布时间】:2016-02-23 21:01:05
【问题描述】:
我有一个在专用服务器“Windows Server 2012 R2”上运行的 ASP.NET 应用程序。该网站自始至终使用 SSL 加密,证书已正确安装在服务器上,并在通过不同浏览器访问时显示为有效。
我现在想通过我的应用程序发送电子邮件,为此我按照本文中的说明设置了一个 SMTP 服务器。 http://www.vsysad.com/2014/09/setup-and-configure-smtp-server-on-windows-server-2012/
按照上面指定的设置 SMTP 服务器后,我可以使用 powershell 发送电子邮件,并且发送没有问题。但是,当我通过我的应用程序执行相同操作时,我收到以下错误
Exception Type: System.Security.Authentication.AuthenticationException
Exception: The remote certificate is invalid according to the validation procedure.
Stack Trace:
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at EmailSender.SendMailSingleRecipient(String recipient, String subject, String message)
从我的应用程序发送电子邮件的代码非常简单,如下所示。
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("no-reply@mysite.com");
mailMessage.To.Add("myemail@email.com");
mailMessage.Subject = "subject"
mailMessage.Body = "message"
SmtpClient smtpClient = new SmtpClient("localhost", 25);
smtpClient.Send(mailMessage);
我已经多次看到相同的问题被报告,但没有任何答案可以为我解决问题。有人可以解释此错误背后的原因以及可能的原因/解决方案。
【问题讨论】:
标签: c# asp.net ssl smtp windows-server-2012