System.Net.Mail.SmtpClient.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                if (InCall && !_cancelled)
                {
                    _cancelled = true;
                    Abort();
                }

                if ((_transport != null))
                {
                    _transport.ReleaseConnection();
                }

                if (_timer != null)
                {
                    _timer.Dispose();
                }

                _disposed = true;
            }
        }
    }

Same methods

SmtpClient::Dispose ( ) : void

Usage Example

 public void sendPurchaseOrderToSupplier()
 {
     MailMessage purchaseOrderEmail = new MailMessage();
     purchaseOrderEmail.To.Add(address);
     purchaseOrderEmail.From = new MailAddress("*****@*****.**");
     purchaseOrderEmail.Subject = "Purchase Order From Williams Engraving and Specialty Supplies";
     Attachment attachment = new Attachment(path, MediaTypeNames.Application.Octet);
     purchaseOrderEmail.Attachments.Add(attachment);
     using (SmtpClient smtp = new SmtpClient())
     {
         try
         {
             smtp.Host = "smtp.gmail.com";
             smtp.Port = 587;
             smtp.EnableSsl = true;
             smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
             smtp.UseDefaultCredentials = false;
             smtp.Credentials = new NetworkCredential("*****@*****.**", "Pa$$word");
             smtp.Send(purchaseOrderEmail);
         }
         catch (SmtpException ex)
         {
             smtp.Dispose();
         }
         finally
         {
             purchaseOrderEmail.Dispose();
             smtp.Dispose();
         }
     }
 }
All Usage Examples Of System.Net.Mail.SmtpClient::Dispose