/// <summary> /// This method is called when asynchronous <b>StartTLS</b> method completes. /// </summary> /// <param name="ar">An IAsyncResult that stores state information and any user defined data for this asynchronous operation.</param> private void StartTlsCallback(IAsyncResult ar) { try{ m_pSmtpClient.EndStartTLS(ar); // Authentication requested, start authenticating. if (!string.IsNullOrEmpty(m_pActiveTarget.UserName)) { m_pSmtpClient.BeginAuthenticate(m_pActiveTarget.UserName, m_pActiveTarget.Password, new AsyncCallback(this.AuthenticateCallback), null); } else { long messageSize = -1; try{ messageSize = m_pRelayItem.MessageStream.Length - m_pRelayItem.MessageStream.Position; } catch { // Stream doesn't support seeking. } m_pSmtpClient.BeginMailFrom(this.From, messageSize, new AsyncCallback(this.MailFromCallback), null); } } catch (Exception x) { Dispose(x); } }