I have recently used Mailkit lib in our project in order replacing .NET SmtpClient.
We have 2 business cases to use the SmtpClient to send emails.
In one instance we use SmtpClient to send queued emails in a separate process and other instance we send emails instantly.
While implementing I noticed that we have to call the Disconnect method of the Client instance.
It was not sure and not clear in the documentation what is the best way to call this method.
So my question, What is the best practice to use this method?
Call mailClient.Disconnect(true) per every message or mailClient.Disconnect(false)?mailClient.Disconnect(...);
Out of interest, if I use the client within a using block, should I require to call Disconnect(...) explicitly after sending a message? I reckon it calls disconnect implicitly when the Dispose() gets executed.
using (var mailClient = new SmtpClient())
{
mailClient.Connect(...);
mailClient.AuthenticationMechanisms.Remove("XOAUTH2");
mailClient.Authenticate(...);
mailClient.Send(message);
mailClient.Disconnect(false);
}
Appreciate your feedback in this regard.