private void Connect_Click(object sender, EventArgs e) { if (this.CheckInputValidationForPop(this.PopServer.Text, this.PopPort.Text, this.PopUserName.Text, this.PopPassword.Text)) { if (Internet.IsConnectedToInternet()) { Thread th = new Thread(new ThreadStart(this.ReceiveEmails)); th.Start(); } else { MessageBox.Show(this, "You must connect to the internet.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void Send_Click(object sender, EventArgs e) { if (this.CheckInputValidation(SmtpServer.Text, SmtpPort.Text, UserName.Text, Password.Text, From.Text, To.Text, Cc.Text, Bcc.Text)) { if (this.EmailValidation(this.From.Text)) { bool isRecipient = false; if (this.To.Text.Length > 0) { if (this.RecipientsEmailValidation(this.To.Text)) { isRecipient = true; } else { MessageBox.Show(this, "Recipients' email address is not in the correct format, in \"To: \" field.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (this.Cc.Text.Length > 0) { if (!(this.RecipientsEmailValidation(this.Cc.Text))) { MessageBox.Show(this, "Recipients' email address is not in the correct format, in \"Cc: \" field.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { isRecipient = true; } } if (this.Bcc.Text.Length > 0) { if (!(this.RecipientsEmailValidation(this.Bcc.Text))) { MessageBox.Show(this, "Recipients' email address is not in the correct format, in \"Bcc: \" field.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { isRecipient = true; } } if (Internet.IsConnectedToInternet()) { if (isRecipient == true) { Rtf2Html rtf = new Rtf2Html(); string Html = rtf.ConvertRtfToHtml(this.MailMessage); MailMessage mail_message = new MailMessage(); mail_message.From = this.From.Text; mail_message.To = this.To.Text; mail_message.CC = this.Cc.Text; mail_message.BCC = this.Bcc.Text; mail_message.Subject = this.Subject.Text; mail_message.MailType = MailEncodingType.HTML; mail_message.MailPriority = MailSendPriority.NORMAL; mail_message.Message = Html; mail_message.Attachments = this.attachments; Thread thread = new Thread(new ParameterizedThreadStart(this.SendEmail)); thread.Start(mail_message); } else { return; } } else { MessageBox.Show(this, "You must connect to the internet.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show(this, "Sender email address is not in the correct format.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <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); } }