Example #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";
            }
        }
        // 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";
            }
        }
Example #3
0
        /// <summary>
        /// Check Smtp Server/Port and Username/Password, return (A new Message) FORM
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bunifuThinButtonFurther_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(bunifuTextboxLogin.text) &&
                !string.IsNullOrEmpty(bunifuMaterialTextboxPassword.Text) &&
                bunifuTextboxLogin.text != "Email address mail" &&
                bunifuMaterialTextboxPassword.Text != "Password")
            {
                try
                {
                    if (Internet.IsConnectedToInternet())
                    {
                        smtp = new SmtpClient(SmtpDialog.SmtpName, Convert.ToInt32(SmtpDialog.SmtpProxy));
                        if (EmailValidation(bunifuTextboxLogin._TextBox.Text))
                        {
                            if (Internet.IsConnectedToInternet())
                            {
                                smtp.UserName = bunifuTextboxLogin.text;
                                smtp.Password = bunifuMaterialTextboxPassword.Text;


                                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(new MailMessage
                                {
                                    From    = bunifuTextboxLogin.text,
                                    To      = "",
                                    Subject = ""
                                });
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "Email address is not in the correct format.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "You must connect to the internet.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (FormatException)
                {
                    _exception_type = "port_error";
                    MessageBox.Show(this, "Smtp Port name is not valid. Please, enter correct Port name", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception exception)
                {
                    var smtpClientException = (SmtpClientException)exception;

                    if (smtpClientException.ErrorMessage.Contains("Smtp server"))
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
                finally
                {
                    if (smtp != null)
                    {
                        if (smtp.errorMessage == _exception_type)
                        {
                            this.Hide();
                            SmtpDialog._flagHideFirstForm = true;
                            Compose compose = new Compose();
                            compose.ShowDialog();
                        }
                        else if (_exception_type == "port_error")
                        {
                            _exception_type = "success";
                        }
                        else if (smtp.errorMessage != "")
                        {
                            MessageBox.Show(this, smtp.errorMessage, "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show(this, "Please enter your email or password", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }