private void StartSendMail(object state) { MailMessage msgMail = null; SmtpClient mailClient = null; try { msgMail = (MailMessage)state; mailClient = new SmtpClient(WebConfig.GetEmailServer(), WebConfig.GetEmailServerPort()); if (_authenticationMethod == "default") { mailClient.UseDefaultCredentials = true; } else { var basicAuthenticationInfo = new NetworkCredential(_basicAuthenUserName, _basicAuthenPassword); mailClient.Credentials = basicAuthenticationInfo; mailClient.EnableSsl = true; } mailClient.Send(msgMail); } catch (Exception e) { Logger.Error("Failed to Send Email:\n", e); } finally { if (mailClient != null) { mailClient.Dispose(); } if (msgMail != null) { msgMail.Dispose(); } } }