コード例 #1
0
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var hostNameType = Uri.CheckHostName(txtSmtpHost.Text.Trim());
         if (hostNameType == UriHostNameType.Unknown)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_host", "Invalid host name"),
                               PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtSmtpHost.SelectAll();
             txtSmtpHost.Focus();
             return;
         }
         var rg    = new Regex(PNStrings.MAIL_PATTERN, RegexOptions.IgnoreCase);
         var match = rg.Match(txtSmtpAddress.Text.Trim());
         if (!match.Success)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_email", "Invalid e-mail address"),
                               PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtSmtpAddress.SelectAll();
             txtSmtpAddress.Focus();
             return;
         }
         if (txtSmtpPort.Text.Trim().StartsWith("0") || Convert.ToInt32(txtSmtpPort.Text.Trim()) > 65535)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_port", "Invalid port number"),
                               PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtSmtpPort.SelectAll();
             txtSmtpPort.Focus();
             return;
         }
         _Client.HostName      = txtSmtpHost.Text.Trim();
         _Client.SenderAddress = txtSmtpAddress.Text.Trim();
         using (var encryptor = new PNEncryptor(PNKeys.ENC_KEY))
         {
             _Client.Password = encryptor.EncryptString(txtSmtpPassword.Password);
         }
         _Client.Port        = Convert.ToInt32(txtSmtpPort.Text.Trim());
         _Client.DisplayName = txtSmtpDisplayName.Text.Trim().Length > 0 ? txtSmtpDisplayName.Text.Trim() : _Client.SenderAddress;
         if (SmtpChanged != null)
         {
             var ev = new SmtpChangedEventArgs(_Client, _Mode);
             SmtpChanged(this, ev);
             if (!ev.Accepted)
             {
                 txtSmtpAddress.SelectAll();
                 txtSmtpAddress.Focus();
                 return;
             }
         }
         DialogResult = true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #2
0
 private void smtpDlg_SmtpChanged(object sender, SmtpChangedEventArgs e)
 {
     try
     {
         if (e.Mode == AddEditMode.Add)
         {
             if (_SmtpClients.Any(sm => sm.SenderAddress == e.Profile.SenderAddress))
             {
                 PNMessageBox.Show(
                     PNLang.Instance.GetMessageText("smtp_same_address",
                         "There is already SMTP profile with the same address"), PNStrings.PROG_NAME,
                     MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 e.Accepted = false;
                 return;
             }
             e.Profile.Id = _SmtpClients.Any() ? _SmtpClients.Max(c => c.Id) + 1 : 0;
             _SmtpClients.Add(e.Profile);
             fillSmtpClients(false);
         }
         else
         {
             if (
                 _SmtpClients.Any(
                     sm => sm.SenderAddress == e.Profile.SenderAddress && sm.Id != e.Profile.Id))
             {
                 PNMessageBox.Show(
                     PNLang.Instance.GetMessageText("smtp_same_address",
                         "There is already SMTP profile with the same address"), PNStrings.PROG_NAME,
                     MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 e.Accepted = false;
                 return;
             }
             var client = _SmtpClients.FirstOrDefault(c => c.Id == e.Profile.Id);
             if (client == null) return;
             client.HostName = e.Profile.HostName;
             client.SenderAddress = e.Profile.SenderAddress;
             client.Port = e.Profile.Port;
             client.Password = e.Profile.Password;
             client.DisplayName = e.Profile.DisplayName;
             fillSmtpClients(false);
         }
         var d = sender as WndSmtp;
         if (d != null) d.SmtpChanged -= smtpDlg_SmtpChanged;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #3
0
ファイル: WndSmtp.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var hostNameType = Uri.CheckHostName(txtSmtpHost.Text.Trim());
         if (hostNameType == UriHostNameType.Unknown)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_host", "Invalid host name"),
                 PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtSmtpHost.SelectAll();
             txtSmtpHost.Focus();
             return;
         }
         var rg = new Regex(PNStrings.MAIL_PATTERN, RegexOptions.IgnoreCase);
         var match = rg.Match(txtSmtpAddress.Text.Trim());
         if (!match.Success)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_email", "Invalid e-mail address"),
                PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtSmtpAddress.SelectAll();
             txtSmtpAddress.Focus();
             return;
         }
         if (txtSmtpPort.Text.Trim().StartsWith("0") || Convert.ToInt32(txtSmtpPort.Text.Trim()) > 65535)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_port", "Invalid port number"),
                PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtSmtpPort.SelectAll();
             txtSmtpPort.Focus();
             return;
         }
         _Client.HostName = txtSmtpHost.Text.Trim();
         _Client.SenderAddress = txtSmtpAddress.Text.Trim();
         using (var encryptor = new PNEncryptor(PNKeys.ENC_KEY))
         {
             _Client.Password = encryptor.EncryptString(txtSmtpPassword.Password);
         }
         _Client.Port = Convert.ToInt32(txtSmtpPort.Text.Trim());
         _Client.DisplayName = txtSmtpDisplayName.Text.Trim().Length > 0 ? txtSmtpDisplayName.Text.Trim() : _Client.SenderAddress;
         if (SmtpChanged != null)
         {
             var ev = new SmtpChangedEventArgs(_Client, _Mode);
             SmtpChanged(this, ev);
             if (!ev.Accepted)
             {
                 txtSmtpAddress.SelectAll();
                 txtSmtpAddress.Focus();
                 return;
             }
         }
         DialogResult = true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }