I have a following method which I call for every MailMessage:
public static string SendEmail(MailMessage email)
{
string rez = "";
try
{
var smtpserver = "10.xxx.xx.xx";
using (SmtpClient mailclient = new SmtpClient())
{
mailclient.Host = smtpserver;
mailclient.Send(email);
}
rez = "OK";
}
catch (Exception ex)
{
rez = "NOT OK: " + ex.Message;
}
return rez;
}
I send 32 email-s at once, and for two of them I got following error from mailclient.Send(): NOT OK: Service not available, closing transmission channel. The server response was: 4.3.2 The maximum number of concurrent connections has exceeded a limit, closing transmission channel
I was wondering if this is because I created a new SmtpClient instance for every mail?
Will the following change fix the problem since there is only one instance of SmtpClient. UnfortunatellyI cannot test it, I can only try it in production.
public static SmtpClient mailclient = new SmtpClient("10.xxx.xx.xx");
public static string SendEmail(MailMessage email)
{
string rez = "";
try
{
mailclient.Send(email);
rez = "OK";
}
catch (Exception ex)
{
rez = "NOT OK: " + ex.Message;
}
return rez;
}
Thanks.