I have the following class:
public class Email
{
public System.Net.Mail.SmtpClient SmtpClient
{
get
{
if (_client == null)
{
_client = new System.Net.Mail.SmtpClient();
}
return _client;
}
}
}
and use it
static Email email = new Email();
(in method)
email.SmtpClient.Send(message);
and after some calls of this code I get exception:
Service not available, closing transmission channel. The server
response was: 4.4.2 service timed out.
why?
This error can be because you exceed the
MessageRateLimitExceeded(which limits how fast you can send multiple messages) or the connection has dropped.There is also other configuration parameters on SMTP servers which can limit how many and how much data you can send per session. The SmtpClient also manage connections in a pool,
so I think it’s better to create a new client after you have sent few messages. You must also Dispose the client to ensure the client sends a QUIT message to servers.
For more information about error situations, read this MSDN Article.