4

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:enter image description here

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.

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:

{"The message received was unexpected or badly formatted"}
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
  • Could you post the inner exception details and/or the full stack trace? – Viccari Apr 22 '13 at 12:15
  • Do you have any firewall rules blocking outbound connections at the box where your Windows app is running? – Viccari Apr 26 '13 at 16:27
  • may be, but i am using the same config in another win app on the same machine and everything is working fine. – Amr Elgarhy Apr 26 '13 at 23:07
  • Sorry if I am diverging a bit, but have you tried to run this app from another machine or from another network? – Viccari Apr 27 '13 at 13:00
  • the same app is not working now on other machines, but other apps with same smtp config are working fine even on the same machine – Amr Elgarhy Apr 27 '13 at 18:07
  • Have you solved the problem? It is several days that we don't get news about the status of your problem. – FeliceM May 13 '13 at 19:58

3 Answers3

5

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

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.

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

James Ogden
  • 852
  • 6
  • 11
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.

FeliceM
  • 4,163
  • 9
  • 48
  • 75
  • A similar question has also been asked here already and there was a solution. http://stackoverflow.com/questions/15098667/mvcmailer-sendasync-fails-with-amazon-ses – FeliceM May 12 '13 at 04:34
  • @AmrElGarhy any development from your side? – FeliceM May 14 '13 at 19:18
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"

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

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 Network Service Authenticated Users

e.g.

winhttpcertcfg -g -c LOCAL_MACHINE\MY -s "CertificateName" -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

"

Community
  • 1
  • 1
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76