Apr 23, 2012 at 2:12 PM
Edited Apr 23, 2012 at 8:55 PM
We spent months trying to troubleshoot why we were receiving SMTP timeout errors on the send email activity..
System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: 4.4.1 Connection timed out at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.Smt
I had dived into the code and it seemed that it was written correctly. I created a test that would create an item in a list every 10 seconds or so, and when each item was created, it would trigger three separate workflows:
1. Workflow to send an email using the normal SharePoint email activity
2. Workflow to send an email using the SPdactivities send email
3. Workflow to send an email using the SPdactivities send email with attachment
The first workflow never failed. The other 2 workflows would occassionally fail with a time out error of 4.7.1 or 4.4.1
Upon further investigation, I learned that it's not the actual activities causing the problem. It's the .NET code itself. SMTPClient.Send() does not have a dispose method and so it never closes the transmission. It waits to
receive a QUIT command from the SMTP server, but it never receives one. Therefore, it times out on its own after 60 seconds. Emails sent within 60 seconds of the first email will get through because they jump on the same connection, even if a new instance
of an SMTPClient is created. However, if an email is sent around that 60 second timeout, then it will fail because it has now hit the time out on the original connection. The SMTPClient.Dispose() would obtain the QUIT command, but this
method is available on the NET 4.0 framework and later. Earlier versions do not support it.
So, the way to get around it in earlier versions of the .NET framework, you could either wrap the code in a try catch, and try to resend the email when an exception occurs, or you can modify the code by adding the ServicePoint.MaxIdleTime
= 1 to instantly send the email:
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from);
//add the code to set the mail content
//send the message
SmtpClient smtp = new SmtpClient(site.WebApplication.OutboundMailServiceInstance.Server.Address);
smtp.ServicePoint.MaxIdleTime = 1;
I hope this helps people that were noticing the same issue!