/// <summary> /// Is called when STARTTLS command has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> private void StartTlsCommandCompleted(SMTP_Client.StartTlsAsyncOP op) { if (op == null) { throw new ArgumentNullException("op"); } try{ if (op.Error != null) { Dispose(op.Error); } else { // Do EHLO/HELO. string hostName = string.IsNullOrEmpty(m_pLocalBindInfo.HostName) ? Dns.GetHostName() : m_pLocalBindInfo.HostName; SMTP_Client.EhloHeloAsyncOP ehloOP = new SMTP_Client.EhloHeloAsyncOP(hostName); ehloOP.CompletedAsync += delegate(object s, EventArgs <SMTP_Client.EhloHeloAsyncOP> e){ EhloCommandCompleted(ehloOP); }; if (!m_pSmtpClient.EhloHeloAsync(ehloOP)) { EhloCommandCompleted(ehloOP); } } } catch (Exception x) { Dispose(x); } }
/// <summary> /// Is called when STARTTLS command has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> private void StartTlsCommandCompleted(SMTP_Client.StartTlsAsyncOP op) { if (op == null) { throw new ArgumentNullException("op"); } try{ if (op.Error != null) { Dispose(op.Error); } else { // Do EHLO/HELO. SMTP_Client.EhloHeloAsyncOP ehloOP = new SMTP_Client.EhloHeloAsyncOP(null); ehloOP.CompletedAsync += delegate(object s, EventArgs <SMTP_Client.EhloHeloAsyncOP> e){ EhloCommandCompleted(ehloOP); }; if (!m_pSmtpClient.EhloHeloAsync(ehloOP)) { EhloCommandCompleted(ehloOP); } } } catch (Exception x) { Dispose(x); } }
/// <summary> /// Is called when EHLO/HELO command has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> private void ConnectCompleted(TCP_Client.ConnectAsyncOP op) { if (op == null) { throw new ArgumentNullException("op"); } try { // Connect failed. if (op.Error != null) { try { // Release IP usage. m_pServer.RemoveIpUsage(m_pActiveTarget.Target.Address); m_pActiveTarget = null; // Connect failed, if there are more target IPs, try next one. if (!this.IsDisposed && !this.IsConnected && m_pTargets.Count > 0) { BeginConnect(); } else { Dispose(op.Error); } } catch (Exception x1) { Dispose(x1); } } // Connect suceeded. else { // Do EHLO/HELO. string hostName = string.IsNullOrEmpty(m_pLocalBindInfo.HostName) ? Dns.GetHostName() : m_pLocalBindInfo.HostName; SMTP_Client.EhloHeloAsyncOP ehloOP = new SMTP_Client.EhloHeloAsyncOP(hostName); ehloOP.CompletedAsync += delegate(object s, EventArgs <SMTP_Client.EhloHeloAsyncOP> e) { EhloCommandCompleted(ehloOP); }; if (!m_pSmtpClient.EhloHeloAsync(ehloOP)) { EhloCommandCompleted(ehloOP); } } } catch (Exception x) { Dispose(x); } }
/// <summary> /// Is called when EHLO/HELO command has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> private void EhloCommandCompleted(SMTP_Client.EhloHeloAsyncOP op) { if (op == null) { throw new ArgumentNullException("op"); } try{ if (op.Error != null) { Dispose(op.Error); } else { // Start TLS requested, start switching to secure. if (!m_pSmtpClient.IsSecureConnection && ((m_pServer.UseTlsIfPossible && IsTlsSupported()) || m_pActiveTarget.SslMode == SslMode.TLS)) { SMTP_Client.StartTlsAsyncOP startTlsOP = new SMTP_Client.StartTlsAsyncOP(null); startTlsOP.CompletedAsync += delegate(object s, EventArgs <SMTP_Client.StartTlsAsyncOP> e){ StartTlsCommandCompleted(startTlsOP); }; if (!m_pSmtpClient.StartTlsAsync(startTlsOP)) { StartTlsCommandCompleted(startTlsOP); } } // Authentication requested, start authenticating. else if (!string.IsNullOrEmpty(m_pActiveTarget.UserName)) { SMTP_Client.AuthAsyncOP authOP = new SMTP_Client.AuthAsyncOP(m_pSmtpClient.AuthGetStrongestMethod(m_pActiveTarget.UserName, m_pActiveTarget.Password)); authOP.CompletedAsync += delegate(object s, EventArgs <SMTP_Client.AuthAsyncOP> e){ AuthCommandCompleted(authOP); }; if (!m_pSmtpClient.AuthAsync(authOP)) { AuthCommandCompleted(authOP); } } // Start MAIL command. else { long messageSize = -1; try{ messageSize = m_pRelayItem.MessageStream.Length - m_pRelayItem.MessageStream.Position; } catch { // Stream doesn't support seeking. } SMTP_Client.MailFromAsyncOP mailOP = new SMTP_Client.MailFromAsyncOP( this.From, messageSize, IsDsnSupported() ? m_pRelayItem.DSN_Ret : SMTP_DSN_Ret.NotSpecified, IsDsnSupported() ? m_pRelayItem.EnvelopeID : null ); mailOP.CompletedAsync += delegate(object s, EventArgs <SMTP_Client.MailFromAsyncOP> e){ MailCommandCompleted(mailOP); }; if (!m_pSmtpClient.MailFromAsync(mailOP)) { MailCommandCompleted(mailOP); } } } } catch (Exception x) { Dispose(x); } }
/// <summary> /// Is called when EHLO/HELO command has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> private void ConnectCompleted(TCP_Client.ConnectAsyncOP op) { if(op == null){ throw new ArgumentNullException("op"); } try{ // Connect failed. if(op.Error != null){ try{ // Release IP usage. m_pServer.RemoveIpUsage(m_pActiveTarget.Target.Address); m_pActiveTarget = null; // Connect failed, if there are more target IPs, try next one. if(!this.IsDisposed && !this.IsConnected && m_pTargets.Count > 0){ BeginConnect(); } else{ Dispose(op.Error); } } catch(Exception x1){ Dispose(x1); } } // Connect suceeded. else{ // Do EHLO/HELO. string hostName = string.IsNullOrEmpty(m_pLocalBindInfo.HostName) ? Dns.GetHostName() : m_pLocalBindInfo.HostName; SMTP_Client.EhloHeloAsyncOP ehloOP = new SMTP_Client.EhloHeloAsyncOP(hostName); ehloOP.CompletedAsync += delegate(object s,EventArgs<SMTP_Client.EhloHeloAsyncOP> e){ EhloCommandCompleted(ehloOP); }; if(!m_pSmtpClient.EhloHeloAsync(ehloOP)){ EhloCommandCompleted(ehloOP); } } } catch(Exception x){ Dispose(x); } }
/// <summary> /// Is called when STARTTLS command has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> private void StartTlsCommandCompleted(SMTP_Client.StartTlsAsyncOP op) { if(op == null){ throw new ArgumentNullException("op"); } try{ if(op.Error != null){ Dispose(op.Error); } else{ // Do EHLO/HELO. SMTP_Client.EhloHeloAsyncOP ehloOP = new SMTP_Client.EhloHeloAsyncOP(null); ehloOP.CompletedAsync += delegate(object s,EventArgs<SMTP_Client.EhloHeloAsyncOP> e){ EhloCommandCompleted(ehloOP); }; if(!m_pSmtpClient.EhloHeloAsync(ehloOP)){ EhloCommandCompleted(ehloOP); } } } catch(Exception x){ Dispose(x); } }