andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 169 forks source link

Errors while sending multiple emails using AWS SES #138

Open akhilrex opened 8 years ago

akhilrex commented 8 years ago

I have a process that sends a large number of emails in parallel using the SendAsync method. I am using AWS as the email provider. Many of these emails throw SmtpExceptions erratically. I have retry mechanisms in place which ensures the emails are eventually sent after some retries but the errors seem to be coming for no reason. Some of the errors being

System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: Timeout waiting for data from client. at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse) at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn) at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args) at System.Net.ClosableStream.Close() at System.Net.Mail.MailWriter.Close() at System.Net.Mail.SmtpClient.Complete(Exception exception, IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


System.Net.Mail.SmtpException: Syntax error in parameters or arguments. The server response was: Invalid RCPT TO address provided at System.Net.Mail.SendMailAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpTransport.EndSendMail(IAsyncResult result) at System.Net.Mail.SmtpClient.SendMailCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

System.Net.Mail.SmtpException: The server committed a protocol violation The server response was: at System.Net.Mail.SendMailAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpTransport.EndSendMail(IAsyncResult result) at System.Net.Mail.SmtpClient.SendMailCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

There is no definitive pattern of these errors. I have done a lot research to figure this out and most of the resources mention disposing the SmtpClient object which Postal is already using. I have tried different ports of AWS as well. Is there any way this can be fixed?