SmtpClient implements IDisposable as of .NET 4.0. ErrorMailModule.SendMail method does not correctly dispose of its SmtpClient. This causes the smtp connection to hang for an extended amount of time. Added benefit of properly closing/disposing of the SmtpClient instance is that an smtp QUIT command can be properly sent to the server.
To maintain compatibility between .NET versions, I suggest implementing the following solution:
var client = new SmtpClient();
using (client as IDisposable) // allow client not to implement IDisposable, but correctly handle the 4.0+ implementation
{
// ... do all the SmtpClient work
client.Send(mail);
}
SmtpClient implements IDisposable as of .NET 4.0. ErrorMailModule.SendMail method does not correctly dispose of its SmtpClient. This causes the smtp connection to hang for an extended amount of time. Added benefit of properly closing/disposing of the SmtpClient instance is that an smtp QUIT command can be properly sent to the server.
To maintain compatibility between .NET versions, I suggest implementing the following solution: