Exemple #1
0
        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);
                }
            }
        }
        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);
                }
            }
        }
Exemple #3
0
        private void bunifuThinButtonSend_Click(object sender, EventArgs e)
        {
            bool isRecipient = false;

            if (this.bunifuMetroTextboxTo.Text.Length > 0)
            {
                if (this.RecipientsEmailValidation(this.bunifuMetroTextboxTo.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.bunifuMetroTextboxCc.Text.Length > 0)
            {
                if (!(this.RecipientsEmailValidation(this.bunifuMetroTextboxCc.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.bunifuMetroTextboxBcc.Text.Length > 0)
            {
                if (!(this.RecipientsEmailValidation(this.bunifuMetroTextboxBcc.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 (isRecipient == true)
            {
                try
                {
                    Rtf2Html rtf  = new Rtf2Html();
                    string   Html = rtf.ConvertRtfToHtml(richTextBoxMailMessage);

                    MailMessage mail_message = new MailMessage();
                    mail_message.From         = LoginEMail.smtp.UserName;
                    mail_message.To           = this.bunifuMetroTextboxTo.Text;
                    mail_message.CC           = this.bunifuMetroTextboxCc.Text;
                    mail_message.BCC          = this.bunifuMetroTextboxBcc.Text;
                    mail_message.Subject      = this.bunifuMetroTextboxSubject.Text;
                    mail_message.MailType     = MailEncodingType.HTML;
                    mail_message.MailPriority = MailSendPriority.NORMAL;
                    mail_message.Message      = Html;
                    mail_message.Attachments  = this.attachments;

                    SendEmail(mail_message);
                    Message_box dialog = new Message_box();
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                MessageBox.Show(this, "Please enter To address", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }