コード例 #1
0
ファイル: SMTP_Client.cs プロジェクト: nbhopson/QMail
        /// <summary>
        /// Starts sending EHLO/HELO command to SMTP server.
        /// </summary>
        /// <param name="op">Asynchronous operation.</param>
        /// <returns>Returns true if aynchronous operation is pending (The <see cref="EhloHeloAsyncOP.CompletedAsync"/> event is raised upon completion of the operation).
        /// Returns false if operation completed synchronously.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when SMTP client is not connected.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
        /// <remarks>NOTE: EHLO command will reset all SMTP session state data.</remarks>
        public bool EhloHeloAsync(EhloHeloAsyncOP op)
        {
            if(this.IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(!this.IsConnected){
                throw new InvalidOperationException("You must connect first.");
            }
            if(op == null){
                throw new ArgumentNullException("op");
            }
            if(op.State != AsyncOP_State.WaitingForStart){
                throw new ArgumentException("Invalid argument 'op' state, 'op' must be in 'AsyncOP_State.WaitingForStart' state.","op");
            }

            return op.Start(this);
        }
コード例 #2
0
ファイル: SMTP_Client.cs プロジェクト: nbhopson/QMail
        /// <summary>
        /// Sends EHLO/HELO command to SMTP server.
        /// </summary>
        /// <param name="hostName">Local host DNS name.</param>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when SMTP client is not connected.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>hostName</b> is null reference.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        /// <exception cref="SMTP_ClientException">Is raised when SMTP server returns error.</exception>
        /// <remarks>NOTE: EHLO command will reset all SMTP session state data.</remarks>
        public void EhloHelo(string hostName)
        {
            if(this.IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(!this.IsConnected){
                throw new InvalidOperationException("You must connect first.");
            }
            if(hostName == null){
                throw new ArgumentNullException("hostName");
            }
            if(hostName == string.Empty){
                throw new ArgumentException("Argument 'hostName' value must be specified.","hostName");
            }

            ManualResetEvent wait = new ManualResetEvent(false);
            using(EhloHeloAsyncOP op = new EhloHeloAsyncOP(hostName)){
                op.CompletedAsync += delegate(object s1,EventArgs<EhloHeloAsyncOP> e1){
                    wait.Set();
                };
                if(!this.EhloHeloAsync(op)){
                    wait.Set();
                }
                wait.WaitOne();
                wait.Close();

                if(op.Error != null){
                    throw op.Error;
                }
            }
        }