Esempio n. 1
0
        /// <summary>
        /// Is called when AUTH 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 AuthCommandCompleted(SMTP_Client.AuthAsyncOP op)
        {
            if(op == null){
                throw new ArgumentNullException("op");
            }

            try{
                if(op.Error != null){
                    Dispose(op.Error);
                }
                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);
            }
        }
Esempio n. 2
0
        /// <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);
            }
        }