Exemple #1
0
        private void SendButton_Click(object sender, EventArgs e) // parametry -> object sender -> przyciśnięcie (coś co wywołało), event args -> parametry zwiazane z kliknięciem
        {
            string text = Send.Text;
            //var b = (Button)sender; //rzutowanie -> rzuca wyjąkiem w przypadku nieudanej konwersji
            var b = sender as Button; //as -> jesli nie uda się sparsować to zwroci null a nie wyjątek

            text = b.Text;

            MailModel model = new MailModel();

            model.FromAddress = tbFrom.Text;
            model.SetMailTo(tbTo.Text);
            model.Subject = title.Text;
            model.Body    = message.Text;
            MailService.Send(model);
        }
Exemple #2
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                MailModel model = new MailModel(tbTo.Text, tbFrom.Text, tbTitle.Text, rtbBody.Text);

                if (!MailService.Send(model))
                {
                    MessageBox.Show("Mail sent successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (IncorrectRecipientException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (IncorrectSenderException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (MailServiceException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }