Exemplo n.º 1
0
        /// <summary>
        /// Sends the specified subject.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="text">The text.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public async Task Send(string subject, string text, params string[] to)
        {
            using (SmtpConnection smtp = new SmtpConnection())
            {
                await smtp.Connect(host, 587);

                await smtp.Ehlo(ehlo_str);

                await smtp.StartTls(host);

                await smtp.Ehlo(ehlo_str);

                await smtp.AuthPlain(login, password);

                await smtp.Mail(login);

                foreach (var item in to)
                {
                    await smtp.Rcpt(item);
                }
                await smtp.Data(MessageFormatter.GetHtml(login, subject, text, to));

                await smtp.Quit();
            }
        }
Exemplo n.º 2
0
        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (SmtpConnection smtpConnection = new SmtpConnection())
                {
                    smtpConnection.Connect("smtp.gmail.com", 587);
                    smtpConnection.ExtendedHello("Hello");
                    smtpConnection.StartTls("smtp.gmail.com");
                    smtpConnection.ExtendedHello("Hello");


                    smtpConnection.AuthPlain(User.Account.Gmail, User.Account.Password);

                    smtpConnection.Mail(User.Account.Gmail);
                    smtpConnection.Recipient(toTextBox.Text);
                    smtpConnection.Data(EmailFormatter.GetText(User.Account.Gmail, subjectTextBox.Text, toTextBox.Text, null, messageText.Text));

                    MessageBox.Show("OK");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                WindowController.Instance.sendMessageWindow.Hide();
                WindowController.Instance.allMessagesWindow.Show();
            }
        }
Exemplo n.º 3
0
        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var userInfo = Login.Split('@');
                var login    = userInfo[0];
                SmtpHost = userInfo[1];
                _smtp.Connect("smtp." + SmtpHost, 587);


                _smtp.ExtendedHello("Hello");
                // переходим в защищенное соединение
                // параметр отвечает за адрес домена, по которому будет проверяется SSL-сертификат
                _smtp.StartTls("smtp." + SmtpHost);
                // снова отправляем extended hello, таковы требования протокола
                _smtp.ExtendedHello("Hello");
                // авторизуемся
                _smtp.AuthPlain(login, Password);
                string email = ToEmailTextBox.Text;
                Regex  regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                Match  match = regex.Match(email);
                if (!match.Success)
                {
                    MessageBox.Show(email + " is incorrect");
                    return;
                }

                _smtp.Mail(Login + "@" + SmtpHost);
                _smtp.Recipient(ToEmailTextBox.Text);
                _smtp.Data(EmailFormatter.GetText(Login + "@" + SmtpHost, TopicTextBox.Text, ToEmailTextBox.Text, null, ContentOfMessageSubHeaderText.Text));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Введите правильно почту получателя");
                return;
            }

            Close();
        }