예제 #1
0
        private void ButtonSendReportClick(object sender, EventArgs e)
        {
            var fromAddress = new MailAddress(_reportCrash.FromEmail);
            var toAddress = new MailAddress(_reportCrash.ToEmail);

            var regexEmail = new Regex(@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
                                       + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
                                            [0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
                                       + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
                                            [0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                                       + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$");
            var subject = "";

            if (string.IsNullOrEmpty(textBoxEmail.Text.Trim()))
            {
                if (_reportCrash.EmailRequired)
                {
                    errorProviderEmail.SetError(textBoxEmail, _resources.GetString("EmailRequiredError"));
                    return;
                }
            }
            else
            {
                errorProviderEmail.SetError(textBoxEmail, "");
                if (!regexEmail.IsMatch(textBoxEmail.Text.Trim()))
                {
                    if (_reportCrash.EmailRequired)
                    {
                        errorProviderEmail.SetError(textBoxEmail, _resources.GetString("InvalidEmailAddressError"));
                        return;
                    }
                }
                else
                {
                    errorProviderEmail.SetError(textBoxEmail, "");
                    fromAddress = new MailAddress(textBoxEmail.Text.Trim());
                    subject = string.Format("{0} {1} Crash Report by {2}", _reportCrash.ApplicationTitle,
                                            _reportCrash.ApplicationVersion, textBoxEmail.Text.Trim());
                }
            }
            if (string.IsNullOrEmpty(subject.Trim()))
            {
                subject = string.Format("{0} {1} Crash Report", _reportCrash.ApplicationTitle,
                                        _reportCrash.ApplicationVersion);
            }

            var smtpClient = new SmtpClient
                {
                    Host = _reportCrash.SmtpHost,
                    Port = _reportCrash.Port,
                    EnableSsl = _reportCrash.EnableSSL,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(_reportCrash.UserName, _reportCrash.Password),
                };

            var message = new MailMessage(fromAddress, toAddress)
                {
                    IsBodyHtml = true,
                    Subject = subject,
                    Body = HtmlReport(),
                };

            if (File.Exists(_reportCrash.ScreenShot) && checkBoxIncludeScreenshot.Checked)
            {
                message.Attachments.Add(new Attachment(_reportCrash.ScreenShot));
            }

            smtpClient.SendCompleted += SmtpClientSendCompleted;
            smtpClient.SendAsync(message, "Crash Report");

            _progressDialog = new ProgressDialog();
            _progressDialog.ShowDialog();
        }
예제 #2
0
        private void ButtonSendReportClick(object sender, EventArgs e)
        {
            var fromAddress = !string.IsNullOrEmpty(_reportCrash.FromEmail) ? new MailAddress(_reportCrash.FromEmail) : null;
            var toAddress   = new MailAddress(_reportCrash.ToEmail);

            const string r0_255     = @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])";
            var          regexEmail = new Regex(@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
                                                + @"((" + r0_255 + @"\." + r0_255 + @"\." + r0_255 + @"\." + r0_255 + @"){1}|"
                                                + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$");
            var subject = "";

            if (string.IsNullOrEmpty(textBoxEmail.Text.Trim()))
            {
                if (_reportCrash.EmailRequired)
                {
                    errorProviderEmail.SetError(textBoxEmail, _resources.GetString("EmailRequiredError"));
                    return;
                }
            }
            else
            {
                errorProviderEmail.SetError(textBoxEmail, "");
                if (!regexEmail.IsMatch(textBoxEmail.Text.Trim()))
                {
                    if (_reportCrash.EmailRequired)
                    {
                        errorProviderEmail.SetError(textBoxEmail, _resources.GetString("InvalidEmailAddressError"));
                        return;
                    }
                }
                else
                {
                    errorProviderEmail.SetError(textBoxEmail, "");
                    fromAddress = new MailAddress(textBoxEmail.Text.Trim());
                    subject     = string.Format("{0} {1} Crash Report by {2}", _reportCrash.ApplicationTitle,
                                                _reportCrash.ApplicationVersion, textBoxEmail.Text.Trim());
                }
            }
            if (string.IsNullOrEmpty(subject.Trim()))
            {
                subject = string.Format("{0} {1} Crash Report", _reportCrash.ApplicationTitle,
                                        _reportCrash.ApplicationVersion);
            }

            if (_reportCrash.AnalyzeWithDoctorDump)
            {
                SendFullReport();
            }
            else
            {
                var smtpClient = new SmtpClient
                {
                    Host                  = _reportCrash.SmtpHost,
                    Port                  = _reportCrash.Port,
                    EnableSsl             = _reportCrash.EnableSSL,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(_reportCrash.UserName, _reportCrash.Password),
                };

                var message = new MailMessage(fromAddress, toAddress)
                {
                    IsBodyHtml = true,
                    Subject    = subject,
                    Body       = HtmlReport(),
                };

                if (File.Exists(_reportCrash.ScreenShot) && checkBoxIncludeScreenshot.Checked)
                {
                    message.Attachments.Add(new Attachment(_reportCrash.ScreenShot));
                }

                smtpClient.SendCompleted += SmtpClientSendCompleted;
                smtpClient.SendAsync(message, "Crash Report");
            }

            _progressDialog = new ProgressDialog();
            _progressDialog.ShowDialog();
        }