MailKit.Net.Smtp.SmtpClient.Dispose C# (CSharp) Method

Dispose() protected method

Releases the unmanaged resources used by the SmtpClient and optionally releases the managed resources.
Releases the unmanaged resources used by the SmtpClient and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; /// false to release only the unmanaged resources.
return void
		protected override void Dispose (bool disposing)
		{
			if (disposing && !disposed) {
				disposed = true;
				Disconnect ();
			}

			base.Dispose (disposed);
		}
	}

Usage Example

Example #1
1
        private async Task SendAsync(MimeMessage mailMessage)
        {
            using (var client = new MailKit.Net.Smtp.SmtpClient())
            {
                try
                {
                    await client.ConnectAsync(_emailConfig.SmtpServer, _emailConfig.PortResetPassword, true);

                    client.AuthenticationMechanisms.Remove("XOAUTH2");
                    await client.AuthenticateAsync(_emailConfig.UserName, _emailConfig.Password);

                    await client.SendAsync(mailMessage);
                }
                catch
                {
                    //log an error message or throw an exception, or both.
                    throw;
                }
                finally
                {
                    await client.DisconnectAsync(true);

                    client.Dispose();
                }
            }
        }
All Usage Examples Of MailKit.Net.Smtp.SmtpClient::Dispose