In Windows Console Application with .NET 3.5 ( I changed the existing .NET 2.0 application to .NET 3.5 )
I have strange problem, the code for sending email works few times(may be 5 to 10 times).
After few times, it fails to send the email with message "Failure sending mail". The same code works after restarting the system. ( which is not the expected solution in production).
Here is the piece of code, I felt , somewhere I have close this SmtpClient Connection. so I set the client to null and called GC.Collect as well, but did not help me.
Please help
private static void SendEmail(MailMessage msg)
{
SmtpClient client = new SmtpClient(GetSMTPServer(), GetSMTPPort());
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.EnableSsl = false;
client.ServicePoint.MaxIdleTime = 1;
//client.Timeout = GetSMTPTimeout(); 30000000
client.Send(msg);
client = null;
GC.Collect();
}