private void SendEmail_Click(object sender, RoutedEventArgs e) { if (HostTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please fill in the hosting provider.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); HostTextbox.Focus(); } else if (EmailTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please enter your email address.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailTextbox.Focus(); } else if (EmailTextbox.Text.Contains("@") == false) { System.Windows.MessageBox.Show("Please enter a valid email address.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailTextbox.Focus(); } else if (PasswordBox.Password == string.Empty) { System.Windows.MessageBox.Show("Please fill in your password.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); PasswordBox.Focus(); } else if (EmailToTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please Enter the email address where you want to send the mail.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailToTextbox.Focus(); } else if (EmailTextbox.Text.Contains("@") == false) { System.Windows.MessageBox.Show("Please enter a valid email address.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailToTextbox.Focus(); } else if (SubjectTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please fill in the subject of your email.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); SubjectTextbox.Focus(); } else if (MessageTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please leave a message.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); MessageTextbox.Focus(); } else { SendEmail.IsEnabled = false; if (HostTextbox.Text.StartsWith("pop3")) { HostTextbox.Text = HostTextbox.Text.Replace("pop3", "smtp"); } else if (HostTextbox.Text.StartsWith("imap")) { HostTextbox.Text = HostTextbox.Text.Replace("imap", "smtp"); } else if (!(HostTextbox.Text.Contains("smtp."))) { HostTextbox.Text = "smtp." + HostTextbox.Text; } ErrorFormat = String.Empty; ErrorSmtp = String.Empty; Host = HostTextbox.Text; EmailFrom = EmailTextbox.Text; EmailTo = EmailToTextbox.Text; Password = PasswordBox.Password; Subject = SubjectTextbox.Text; Message = MessageTextbox.Text; AttachmentPath = AttachmentTextbox.Text; StatusTextBlock.Foreground = Brushes.Black; StatusTextBlock.Text = "Sending..."; BackgroundWorker.RunWorkerAsync(); } }
private void SubjectTextbox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { SubjectTextbox.SelectAll(); }