在windows应用程序中使用amazon ses发送电子邮件时,调用SSPI失败

时间:2021-07-27 18:09:07

I am using amazon ses to send emails, and I use the same config inside a website and windows application.
The website is sending emails normally but the windows application gives me this error and not emails sent:在windows应用程序中使用amazon ses发送电子邮件时,调用SSPI失败

我正在使用amazon se发送电子邮件,我在网站和windows应用程序中使用相同的配置。网站通常会发送电子邮件,但windows应用程序会给我这个错误,而不是发送邮件:

note that when i change the smtp config in the windows app to something like gmail it works fine, the problem happen with just amazon ses and started to happen just today, before that ses was working fine on the windows app.
Also note that both the website and windows app are working now local.

注意,当我改变的smtp配置windows应用程序类似gmail效果好,问题发生在亚马逊ses和今天开始发生,在此之前ses在windows应用程序工作正常。还要注意,两个网站和windows应用程序现在工作的地方。

Stack Trace:

堆栈跟踪:

   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:

InnerException:

{"The message received was unexpected or badly formatted"}

3 个解决方案

#1


3  

I had the same problem, which in the end came down to the SecurityProtocol in effect when trying to connect.

我遇到了同样的问题,最后归结为SecurityProtocol,实际上是在尝试连接时。

Adding

添加

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

before the client.Send resolved it for me (we change it to Ssl3 elsewhere to talk to a different service) It would be nice if this (and ServerCertificateValidationCallback) wasn't a global if anyone on the .Net team is reading.

在客户端。为我发送已解析的它(我们将它更改为Ssl3以与另一个服务进行对话)如果这个(和ServerCertificateValidationCallback)不是全局的(如果. net团队中的任何人正在阅读的话)那就太好了。

I don't know if this is a 'feature' of SES or me just assuming magic should work, but you can see some history here: https://forums.aws.amazon.com/thread.jspa?messageID=472516

我不知道这是不是SES的一个“特性”,或者我只是假设魔法应该起作用,但你可以在这里看到一些历史:https://forums.aws.amazon.com/thread.jspa?messageID=472516。

#2


0  

Try to check your SPN (ServicePrincipalName) config. This problem sound like something went corrupted or modified somewhere in your configuration. If the logon account of a service instance changes, the SPNs must be re-registered under the new account.

尝试检查您的SPN (ServicePrincipalName)配置。这个问题听起来像是某些东西损坏或修改了您的配置。如果服务实例的登录帐户发生更改,则必须在新帐户下重新注册spn。

#3


0  

Take a look at this SO post, from reading around on the net a lot of people point to the certificate being the issue, and I'm wondering if the 'validation' file you use is in effect the wrong one; they solved it by replacing the ".pem file with .p12"

看看这篇文章,从网上的阅读,很多人指出证书就是问题所在,我想知道你使用的“验证”文件实际上是不是错误的;他们通过替换"与.p12 pem文件”

Also take a look at this MS Hotfix that sounds a lot like your problem.

还可以看看这个MS Hotfix听起来很像你的问题。

Also as FeliceM suggests it could be an account issue: (Taken from)

正如费利西姆所言,这也可能是一个账户问题。

" Aspnet runs under a different account so you have to use WinHttpCertCfg.exe tool to allow the following account to access the certificate which you should install in Local Computer Personal/Trusted folders..

Aspnet在不同的帐户下运行,所以您必须使用WinHttpCertCfg。exe工具允许以下帐户访问证书,您应该将证书安装在本地计算机个人/受信任文件夹中。

ASPNET Network Service Authenticated Users

ASPNET网络服务认证用户。

e.g.

如。

winhttpcertcfg -g -c LOCAL_MACHINE\MY -s "CertificateName" -a "ASPNET"

winhttpcertcfg -g -c LOCAL_MACHINE\MY -s " certificate atename " -a "ASPNET"

where certificate name is the friendly name of your certificate.

证书名称是证书的友好名称。

You can get the tool and information from the link below:

你可透过以下连结取得工具及资料:

http://msdn.microsoft.com/en-us/library/aa384088%28VS.85%29.aspx#%5Fusing

http://msdn.microsoft.com/en-us/library/aa384088%28VS.85%29.aspx % 5融合

"

#1


3  

I had the same problem, which in the end came down to the SecurityProtocol in effect when trying to connect.

我遇到了同样的问题,最后归结为SecurityProtocol,实际上是在尝试连接时。

Adding

添加

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

before the client.Send resolved it for me (we change it to Ssl3 elsewhere to talk to a different service) It would be nice if this (and ServerCertificateValidationCallback) wasn't a global if anyone on the .Net team is reading.

在客户端。为我发送已解析的它(我们将它更改为Ssl3以与另一个服务进行对话)如果这个(和ServerCertificateValidationCallback)不是全局的(如果. net团队中的任何人正在阅读的话)那就太好了。

I don't know if this is a 'feature' of SES or me just assuming magic should work, but you can see some history here: https://forums.aws.amazon.com/thread.jspa?messageID=472516

我不知道这是不是SES的一个“特性”,或者我只是假设魔法应该起作用,但你可以在这里看到一些历史:https://forums.aws.amazon.com/thread.jspa?messageID=472516。

#2


0  

Try to check your SPN (ServicePrincipalName) config. This problem sound like something went corrupted or modified somewhere in your configuration. If the logon account of a service instance changes, the SPNs must be re-registered under the new account.

尝试检查您的SPN (ServicePrincipalName)配置。这个问题听起来像是某些东西损坏或修改了您的配置。如果服务实例的登录帐户发生更改,则必须在新帐户下重新注册spn。

#3


0  

Take a look at this SO post, from reading around on the net a lot of people point to the certificate being the issue, and I'm wondering if the 'validation' file you use is in effect the wrong one; they solved it by replacing the ".pem file with .p12"

看看这篇文章,从网上的阅读,很多人指出证书就是问题所在,我想知道你使用的“验证”文件实际上是不是错误的;他们通过替换"与.p12 pem文件”

Also take a look at this MS Hotfix that sounds a lot like your problem.

还可以看看这个MS Hotfix听起来很像你的问题。

Also as FeliceM suggests it could be an account issue: (Taken from)

正如费利西姆所言,这也可能是一个账户问题。

" Aspnet runs under a different account so you have to use WinHttpCertCfg.exe tool to allow the following account to access the certificate which you should install in Local Computer Personal/Trusted folders..

Aspnet在不同的帐户下运行,所以您必须使用WinHttpCertCfg。exe工具允许以下帐户访问证书,您应该将证书安装在本地计算机个人/受信任文件夹中。

ASPNET Network Service Authenticated Users

ASPNET网络服务认证用户。

e.g.

如。

winhttpcertcfg -g -c LOCAL_MACHINE\MY -s "CertificateName" -a "ASPNET"

winhttpcertcfg -g -c LOCAL_MACHINE\MY -s " certificate atename " -a "ASPNET"

where certificate name is the friendly name of your certificate.

证书名称是证书的友好名称。

You can get the tool and information from the link below:

你可透过以下连结取得工具及资料:

http://msdn.microsoft.com/en-us/library/aa384088%28VS.85%29.aspx#%5Fusing

http://msdn.microsoft.com/en-us/library/aa384088%28VS.85%29.aspx % 5融合

"