Esempio n. 1
0
        private void BtnSend_Click(object sender, EventArgs e)
        {
            try
            {
                MailAddress from    = new MailAddress(email);
                MailAddress to      = new MailAddress(TextBoxTo.Text);
                MailMessage message = new MailMessage(from, to)
                {
                    Subject    = TextBoxTatle.Text,
                    IsBodyHtml = false,
                    Body       = TextBoxText.Text,
                };

                if (file != "")
                {
                    message.Attachments.Add(new Attachment($"{file}"));
                }
                smtp.Send(message);
                MessageBox.Show("Сообщение отправлено!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Неверный формат электронной почты. Почта должна иметь окончания - ****@****.**");
                TextBoxTo.Clear();
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Строка с адресом не должна быть пуста");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void PrjSelect() //Изменение выбора в проектах
        {
            DataRowView drv = (DataRowView)DataGridPrj.SelectedItem;

            if (drv == null)
            {
                return;
            }
            _prj.PrjId = drv.Row[0].ToString();
            _stt       = new Stt(_ctg, _prj);

            switch (_stt.SttFromOrTo)
            {
            case "stt_id_from":
                _csh.SttIdFrom      = _stt;
                TextBoxSumFrom.Text = _csh.GetTotalSum(_csh.SttIdFrom);
                TextBoxFrom.Text    = _csh.SttIdFrom.SttName;
                TextBoxTo.Focus();
                break;

            case "stt_id_to":
                _csh.SttIdTo      = _stt;
                TextBoxSumTo.Text = _csh.GetTotalSum(_csh.SttIdTo);
                TextBoxTo.Text    = _csh.SttIdTo.SttName;
                TextBoxSum.Focus();
                break;
            }
            try
            {
                if (_csh.SttIdFrom.SttName != "" && _csh.SttIdTo.SttName != "")
                {
                    ButtonAdd.IsEnabled = true;
                }
            }
            catch
            {
                ButtonAdd.IsEnabled = false;
            }
        }
Esempio n. 3
0
        private void ButtonSend_Click(object sender, System.EventArgs e)
        {
            ButtonSend.Enabled       = false;
            ButtonCancel.Enabled     = true;
            ButtonClearToken.Enabled = false;
            _isCancelSending         = false;

            try
            {
                // request access token if it is not existed.
                _doOauth();

                if (TextBoxTo.Text.Length == 0 &&
                    TextBoxCc.Text.Length == 0)
                {
                    throw new ArgumentNullException("To, Cc", "Please input To or Cc!, the format can be [email protected] or Tester<*****@*****.**>, please use , or ; to separate multiple recipients");
                }

                // If You didn't input from address, authenticated user's email address is used automatically.");

                SmtpClient smtp = new SmtpClient();

                // To generate a log file for SMTP transaction, please use
                // oSmtp.LogFileName = "c:\\smtp.log";

                // Catching the following events is not necessary,
                // just make the application more user friendly.

                // If you use the object in asp.net/windows service or non-gui application,
                // You need not to catch the following events.
                // To learn more detail, please refer to the code in EASendMail EventHandler region
                smtp.OnIdle              += new SmtpClient.OnIdleEventHandler(OnIdle);
                smtp.OnAuthorized        += new SmtpClient.OnAuthorizedEventHandler(OnAuthorized);
                smtp.OnConnected         += new SmtpClient.OnConnectedEventHandler(OnConnected);
                smtp.OnSecuring          += new SmtpClient.OnSecuringEventHandler(OnSecuring);
                smtp.OnSendingDataStream += new SmtpClient.OnSendingDataStreamEventHandler(OnSendingDataStream);

                // create SmtpServer based on settings of Form Control.
                SmtpServer server = _createSmtpServer();

                // create SmtpMail based on settings of Form Controls.
                SmtpMail mail = _createMail();

                StatusBarSend.Text    = "Connecting ... ";
                ProgressBarSend.Value = 0;

                smtp.SendMail(server, mail);

                MessageBox.Show(string.Format("The message was sent to {0} successfully!",
                                              smtp.CurrentSmtpServer.Server));

                StatusBarSend.Text = "Completed";
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
                StatusBarSend.Text = string.Format("Exception: {0}", exp.Message);
                if (exp is ArgumentNullException)
                {
                    TextBoxTo.Select();
                }
                else
                {
                    _oauthWrapper.Provider.ClearToken();
                }
            }

            ButtonSend.Enabled       = true;
            ButtonCancel.Enabled     = false;
            ButtonClearToken.Enabled = (_oauthWrapper.Provider.AccessToken.Length != 0);
        }
Esempio n. 4
0
 private void TextBoxSumFrom_TextChanged(object sender, TextChangedEventArgs e)
 {
     try { TextBoxTo.Focus(); }
     catch { }
 }