private bool SaveEmailAlertOptions() { // Validate input. if (IsEmailAlertsEnabled.IsChecked == true) { var regex = new Regex("^\\d+$"); if (SmtpServer.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid address for your outgoing mail server.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); SmtpServer.Focus(); return(false); } else if (SmtpPort.Text.Length == 0 || !regex.IsMatch(SmtpPort.Text)) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid port number. The standard is 25.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); SmtpPort.Focus(); return(false); } else if (EmailRecipientAddress.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid recipient email address. This is the address that will receive alerts.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); EmailRecipientAddress.Focus(); return(false); } else if (EmailFromAddress.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid 'from' address. This address will appear as the sender for any alerts that are sent.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); EmailFromAddress.Focus(); return(false); } if (IsSmtpAuthenticationRequired.IsChecked == true) { ApplicationOptions.IsEmailAuthenticationRequired = true; if (SmtpUsername.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid username for authenticating to your mail server.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); SmtpUsername.Focus(); return(false); } } else { ApplicationOptions.IsEmailAuthenticationRequired = false; SmtpUsername.Text = string.Empty; SmtpPassword.Password = string.Empty; } ApplicationOptions.IsEmailAlertEnabled = true; ApplicationOptions.EmailServer = SmtpServer.Text; ApplicationOptions.EmailPort = SmtpPort.Text; ApplicationOptions.EmailUser = SmtpUsername.Text; ApplicationOptions.EmailPassword = SmtpPassword.Password; ApplicationOptions.EmailRecipient = EmailRecipientAddress.Text; ApplicationOptions.EmailFromAddress = EmailFromAddress.Text; if (IsSmtpAuthenticationRequired.IsChecked == true && SaveAsDefaults.IsChecked == true) { MessageBox.Show( "You have chosen to save your SMTP credentials to disk." + Environment.NewLine + Environment.NewLine + "While the data is stored in an encrypted format, anyone with access to your vmPing configuration file can decrypt the data.", "vmPing Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } return(true); } else { ApplicationOptions.IsEmailAlertEnabled = false; return(true); } }
private bool SaveEmailAlertOptions() { // Validate input. if (IsEmailAlertsEnabled.IsChecked == true) { var regex = new Regex("^\\d+$"); if (SmtpServer.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid address for your outgoing mail server.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); SmtpServer.Focus(); return(false); } else if (SmtpPort.Text.Length == 0 || !regex.IsMatch(SmtpPort.Text)) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid port number. The standard is 25.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); SmtpPort.Focus(); return(false); } else if (EmailRecipientAddress.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid recipient email address. This is the address that will receive alerts.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); EmailRecipientAddress.Focus(); return(false); } else if (EmailFromAddress.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid 'from' address. This address will appear as the sender for any alerts that are sent.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); EmailFromAddress.Focus(); return(false); } if (IsSmtpAuthenticationRequired.IsChecked == true) { ApplicationOptions.IsEmailAuthenticationRequired = true; if (SmtpUsername.Text.Length == 0) { EmailAlertsTab.Focus(); MessageBox.Show( "Please enter a valid username for authenticating to your mail server.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); SmtpUsername.Focus(); return(false); } } ApplicationOptions.IsEmailAlertEnabled = true; ApplicationOptions.EmailServer = SmtpServer.Text; ApplicationOptions.EmailPort = SmtpPort.Text; ApplicationOptions.EmailUser = SmtpUsername.Text; ApplicationOptions.EmailPassword = SmtpPassword.Password; ApplicationOptions.EmailRecipient = EmailRecipientAddress.Text; ApplicationOptions.EmailFromAddress = EmailFromAddress.Text; return(true); } else { return(true); } }