示例#1
0
        // Helping Methods for Smtp Client user interface
        private void SendEmail(object mail_msg)
        {
            try
            {
                MailMessage mail_message = (MailMessage)mail_msg;

                SmtpClient smtp = new SmtpClient(this.SmtpServer.Text, Convert.ToInt32(this.SmtpPort.Text));
                smtp.UserName = this.UserName.Text;
                smtp.Password = this.Password.Text;

                this.EnableDisableSendButton(false);

                smtp.ConnectionEstablishing += new ConnectEventHandler(smtp_ConnectionEstablishing);
                smtp.ConnectionEstablished += new ConnectEventHandler(smtp_ConnectionEstablished);
                smtp.AuthenticationBegan += new AuthenticateEventHandler(smtp_AuthenticationBegan);
                smtp.AuthenticationFinished += new AuthenticateEventHandler(smtp_AuthenticationFinished);
                smtp.StartedDataTransfer += new DataTransferEventHandler(smtp_StartedDataTransfer);
                smtp.EndedDataTransfer += new DataTransferEventHandler(smtp_EndedDataTransfer);
                smtp.Disconnected += new DisconnectEventHandler(smtp_Disconnected);

                smtp.SendMail(mail_message);
                MessageBox.Show(this,"Email message has sent.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (SmtpClientException obj)
            {
                MessageBox.Show(this, obj.ErrorMessage, "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.EnableDisableSendButton(true);
                this.ProgressLabel.Text = "Email Client";
            }
        }