コード例 #1
0
        /// SMTPメールサーバーへLogin認証でログインします。
        /// <summary>
        /// SMTPメールサーバーへLogin認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean AuthenticateByLogin()
        {
            SmtpCommandResult rs = null;

            if (this.EnsureOpen() == SmtpConnectionState.Connected)
            {
                rs = this.Execute("Auth Login");
                if (rs.StatusCode != SmtpCommandResultCode.WaitingForAuthentication)
                {
                    return(false);
                }
                //ユーザー名送信
                rs = this.Execute(Base64Converter.Encode(Encoding.UTF8.GetBytes(this.UserName)));
                if (rs.StatusCode != SmtpCommandResultCode.WaitingForAuthentication)
                {
                    return(false);
                }
                //パスワード送信
                rs = this.Execute(Base64Converter.Encode(Encoding.UTF8.GetBytes(this.Password)));
                if (rs.StatusCode == SmtpCommandResultCode.AuthenticationSuccessful)
                {
                    this._State = SmtpConnectionState.Authenticated;
                }
            }
            return(this._State == SmtpConnectionState.Authenticated);
        }
コード例 #2
0
ファイル: SmtpClient.cs プロジェクト: hungud/higlabo
        /// サーバーからのレスポンスの受信時に現在の状態に基づいて状態を変化させます。
        /// <summary>
        /// サーバーからのレスポンスの受信時に現在の状態に基づいて状態を変化させます。
        /// </summary>
        private void SetSmtpCommandState()
        {
            this.Commnicating = false;
            switch (this._State)
            {
            case SmtpConnectionState.MailFromCommandExecuting: this._State = SmtpConnectionState.MailFromCommandExecuted; break;

            case SmtpConnectionState.RcptToCommandExecuted: this._State = SmtpConnectionState.RcptToCommandExecuted; break;

            case SmtpConnectionState.DataCommandExecuting: this._State = SmtpConnectionState.DataCommandExecuted; break;
            }
        }
コード例 #3
0
ファイル: SmtpClient.cs プロジェクト: hungud/higlabo
 /// SMTPコマンドの種類に基づいて状態を変化させます。
 /// <summary>
 /// SMTPコマンドの種類に基づいて状態を変化させます。
 /// </summary>
 /// <param name="command"></param>
 private void SetSmtpCommandState(SmtpCommand command)
 {
     if (command is MailCommand)
     {
         this._State = SmtpConnectionState.MailFromCommandExecuting;
     }
     else if (command is RcptCommand)
     {
         this._State = SmtpConnectionState.RcptToCommandExecuting;
     }
     else if (command is DataCommand)
     {
         this._State = SmtpConnectionState.DataCommandExecuting;
     }
 }
コード例 #4
0
ファイル: SmtpClient.cs プロジェクト: hungud/higlabo
 /// サーバーへの接続を開きます。
 /// <summary>
 /// サーバーへの接続を開きます。
 /// </summary>
 public SmtpConnectionState Open()
 {
     if (this.Connect() == true)
     {
         var rs = this.GetResponse();
         if (rs.StatusCode == SmtpCommandResultCode.ServiceReady)
         {
             this._State = SmtpConnectionState.Connected;
         }
         else
         {
             this.Close();
         }
     }
     else
     {
         this._State = SmtpConnectionState.Disconnected;
     }
     return(this._State);
 }
コード例 #5
0
ファイル: SmtpClient.cs プロジェクト: Domcik8/University
        /// SMTPメールサーバーへPlain認証でログインします。
        /// <summary>
        /// SMTPメールサーバーへPlain認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean AuthenticateByPlain()
        {
            SmtpCommandResult rs = null;

            if (this.EnsureOpen() == SmtpConnectionState.Connected)
            {
                rs = this.Execute("Auth Plain");
                if (rs.StatusCode != SmtpCommandResultCode.WaitingForAuthentication)
                {
                    return(false);
                }
                //ユーザー名&パスワードの文字列を送信
                rs = this.Execute(MailParser.ToBase64String(String.Format("{0}\0{0}\0{1}", this.UserName, this.Password)));
                if (rs.StatusCode == SmtpCommandResultCode.AuthenticationSuccessful)
                {
                    this._State = SmtpConnectionState.Authenticated;
                }
            }
            return(this._State == SmtpConnectionState.Authenticated);
        }
コード例 #6
0
ファイル: SmtpClient.cs プロジェクト: hungud/higlabo
        /// SMTPメールサーバーへCRAM-MD5認証でログインします。
        /// <summary>
        /// SMTPメールサーバーへCRAM-MD5認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean AuthenticateByCramMD5()
        {
            SmtpCommandResult rs = null;

            if (this.EnsureOpen() == SmtpConnectionState.Connected)
            {
                rs = this.Execute("Auth CRAM-MD5");
                if (rs.StatusCode != SmtpCommandResultCode.WaitingForAuthentication)
                {
                    return(false);
                }
                //ユーザー名+チャレンジ文字列をBase64エンコードした文字列を送信
                String s = SmtpClient.ToCramMd5String(rs.Message, this.UserName, this.Password);
                rs = this.Execute(s);
                if (rs.StatusCode == SmtpCommandResultCode.AuthenticationSuccessful)
                {
                    this._State = SmtpConnectionState.Authenticated;
                }
            }
            return(this._State == SmtpConnectionState.Authenticated);
        }
コード例 #7
0
ファイル: SmtpClient.cs プロジェクト: fengweijp/higlabo
 /// サーバーからのレスポンスの受信時に現在の状態に基づいて状態を変化させます。
 /// <summary>
 /// サーバーからのレスポンスの受信時に現在の状態に基づいて状態を変化させます。
 /// </summary>
 private void SetSmtpCommandState()
 {
     this.Commnicating = false;
     switch (this._State)
     {
         case SmtpConnectionState.MailFromCommandExecuting: this._State = SmtpConnectionState.MailFromCommandExecuted; break;
         case SmtpConnectionState.RcptToCommandExecuted: this._State = SmtpConnectionState.RcptToCommandExecuted; break;
         case SmtpConnectionState.DataCommandExecuting: this._State = SmtpConnectionState.DataCommandExecuted; break;
     }
 }
コード例 #8
0
ファイル: SmtpClient.cs プロジェクト: fengweijp/higlabo
 /// SMTPコマンドの種類に基づいて状態を変化させます。
 /// <summary>
 /// SMTPコマンドの種類に基づいて状態を変化させます。
 /// </summary>
 /// <param name="command"></param>
 private void SetSmtpCommandState(SmtpCommand command)
 {
     if (command is MailCommand)
     {
         this._State = SmtpConnectionState.MailFromCommandExecuting;
     }
     else if (command is RcptCommand)
     {
         this._State = SmtpConnectionState.RcptToCommandExecuting;
     }
     else if (command is DataCommand)
     {
         this._State = SmtpConnectionState.DataCommandExecuting;
     }
 }
コード例 #9
0
ファイル: SmtpClient.cs プロジェクト: fengweijp/higlabo
 /// サーバーへの接続を開きます。
 /// <summary>
 /// サーバーへの接続を開きます。
 /// </summary>
 public SmtpConnectionState Open()
 {
     if (this.Connect() == true)
     {
         var rs = this.GetResponse();
         if (rs.StatusCode == SmtpCommandResultCode.ServiceReady)
         {
             this._State = SmtpConnectionState.Connected;
         }
         else
         {
             this.Close();
         }
     }
     else
     {
         this._State = SmtpConnectionState.Disconnected;
     }
     return this._State;
 }
コード例 #10
0
ファイル: SmtpClient.cs プロジェクト: fengweijp/higlabo
        /// SMTPメールサーバーへPlain認証でログインします。
        /// <summary>
        /// SMTPメールサーバーへPlain認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean AuthenticateByPlain()
        {
            SmtpCommandResult rs = null;

            if (this.EnsureOpen() == SmtpConnectionState.Connected)
            {
                rs = this.Execute("Auth Plain");
                if (rs.StatusCode != SmtpCommandResultCode.WaitingForAuthentication)
                { return false; }
                //ユーザー名&パスワードの文字列を送信
                rs = this.Execute(Base64Converter.Encode(Encoding.UTF8.GetBytes(String.Format("{0}\0{0}\0{1}", this.UserName, this.Password))));
                if (rs.StatusCode == SmtpCommandResultCode.AuthenticationSuccessful)
                {
                    this._State = SmtpConnectionState.Authenticated;
                }
            }
            return this._State == SmtpConnectionState.Authenticated;
        }
コード例 #11
0
ファイル: SmtpClient.cs プロジェクト: fengweijp/higlabo
        /// SMTPメールサーバーへCRAM-MD5認証でログインします。
        /// <summary>
        /// SMTPメールサーバーへCRAM-MD5認証でログインします。
        /// </summary>
        /// <returns></returns>
        public Boolean AuthenticateByCramMD5()
        {
            SmtpCommandResult rs = null;

            if (this.EnsureOpen() == SmtpConnectionState.Connected)
            {
                rs = this.Execute("Auth CRAM-MD5");
                if (rs.StatusCode != SmtpCommandResultCode.WaitingForAuthentication)
                { return false; }
                //ユーザー名+チャレンジ文字列をBase64エンコードした文字列を送信
                String s = SmtpClient.ToCramMd5String(rs.Message, this.UserName, this.Password);
                rs = this.Execute(s);
                if (rs.StatusCode == SmtpCommandResultCode.AuthenticationSuccessful)
                {
                    this._State = SmtpConnectionState.Authenticated;
                }
            }
            return this._State == SmtpConnectionState.Authenticated;
        }