We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.EMail: SmtpClient conection leak?

Hi,


I’m currently facing many open smtp connections on my mail server. Do send mails I use the following code:

using (var client = new SmtpClient(Server, UserName, Password)
{
Encoding = Encoding.UTF8,
Port = Port,
AuthenticationMethod = SmtpAuthentication.Auto,
//SecurityOptions = EnableSsl ? SecurityOptions.SSLImplicit : SecurityOptions.None
};
if (Timeout != TimeSpan.Zero)
{
client.Timeout = client.ConnectionTimeout = (int) Timeout.TotalMilliseconds;
}

client.Send(…)
}

Is there any way that this code does not close smtp connections.
Do I have to call .Disonnect() manually?

Thank you,
Wolfgang

Hi Wolfgang,


Thank you for writing to Aspose support team.

The available documentation doesn’t say anything about closing of smtp connections. Since the client is used within a using clause, it will dispose the client object certainly after execution. You may check the activity log after the execution is done and see if still reports some activity. Its better to call the client.Disconnect at the end of your code for safe disconnection though.