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); } } }