我正在使用Amazon ses发送电子邮件,并且在网站和Windows应用程序中使用相同的配置。
该网站正常发送电子邮件,但Windows应用程序给我此错误,而不是发送电子邮件:
请注意,当我将Windows应用程序中的smtp配置更改为类似gmail的东西时,它可以正常工作,该问题仅发生在亚马逊ses上,并且直到今天ses才在Windows应用程序上正常运行时才开始发生。
另请注意,网站和Windows应用程序现在都可以在本地运行。
堆栈跟踪:
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, 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.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, 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.Net.TlsStream.CallProcessAuthentication(Object state)
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.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Mail.EmailSender.SendMail(MailMessage mail) in e:\Mail\EmailSender.cs:line 175
InnerException:
{"The message received was unexpected or badly formatted"}
最佳答案
我遇到了同样的问题,最后归结为尝试连接时生效的SecurityProtocol。
新增中
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
在为我解决该问题之前(Send为我解决了该问题(我们将其更改为Ssl3,以便与其他服务进行通信))如果.Net团队中的任何人正在阅读,那么(如果不是)(和ServerCertificateValidationCallback)不是全局的,那就太好了。
我不知道这是否是SES的“功能”,或者我只是假设魔术应该起作用,但是您可以在此处看到一些历史记录:
https://forums.aws.amazon.com/thread.jspa?messageID=472516