Ejemplo n.º 1
0
        public Connection(int connectionID, Socket client, ProcessData processData)
        {
            // Initialize members
            _connectionId = connectionID;
            _client = client;
            _stringBuffer = new StringBuilder();
            _receiveBuffer = new byte[_bufferSize + 1];
            _processData = processData;
            _connected = true;
            _lastActivity = DateTime.Now;
            _session = new SmtpSession();
            BeginReceive();

            Send("220 {0}", Dns.GetHostName().ToLower());
        }
Ejemplo n.º 2
0
        void sendButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(server.Text) || string.IsNullOrEmpty(from.Text) || string.IsNullOrEmpty(to.Text))
            {
                MessageBox.Show("All the text boxes are required, fill them in please.", "Papercut", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if(!emailRegex.IsMatch(from.Text) || !emailRegex.IsMatch(to.Text))
            {
                MessageBox.Show("You need to enter valid email addresses.", "Papercut", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            SmtpSession session = new SmtpSession();
            session.Sender = server.Text.Trim();
            session.MailFrom = from.Text;
            session.Recipients.Add(to.Text);
            session.Message = File.ReadAllBytes(messageFilename);

            worker = new BackgroundWorker();

            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                SmtpSession _session = args.Argument as SmtpSession;
                SmtpClient client = new SmtpClient(_session);
                client.Send();
            };

            worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                // Save settings for the next time
                Settings.Default.ForwardServer = server.Text;
                Settings.Default.ForwardTo = to.Text;
                Settings.Default.ForwardFrom = from.Text;
                Settings.Default.Save();

                working = false;
                sendingLabel.Visibility = Visibility.Hidden;
                DialogResult = true;
            };

            working = true;
            sendButton.IsEnabled = false;
            sendingLabel.Visibility = Visibility.Visible;
            worker.RunWorkerAsync(session);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SmtpClient"/> class.
 /// </summary>
 /// <param name="session">
 /// The session.
 /// </param>
 public SmtpClient(SmtpSession session)
 {
     this.session = session;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// The send button_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.server.Text) || string.IsNullOrEmpty([email protected])
                    || string.IsNullOrEmpty(this.to.Text))
            {
                MessageBox.Show(
                    "All the text boxes are required, fill them in please.", "Papercut", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (!emailRegex.IsMatch([email protected]) || !emailRegex.IsMatch(this.to.Text))
            {
                MessageBox.Show(
                    "You need to enter valid email addresses.", "Papercut", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            var session = new SmtpSession { Sender = this.server.Text.Trim(), MailFrom = [email protected] };
            session.Recipients.Add(this.to.Text);
            session.Message = File.ReadAllBytes(this.messageFilename);

            this.worker = Task.Factory.StartNew(
                () =>
                    {
                        using (var client = new SmtpClient(session))
                        {
                            client.Send();
                        }
                    });

            this.worker.ContinueWith(
                (t) =>
                    {
                        // Save settings for the next time
                        Settings.Default.ForwardServer = this.server.Text;
                        Settings.Default.ForwardTo = this.to.Text;
                        Settings.Default.ForwardFrom = [email protected];
                        Settings.Default.Save();

                        this.working = false;
                        this.sendingLabel.Visibility = Visibility.Hidden;
                        this.DialogResult = true;
                    },
                TaskScheduler.FromCurrentSynchronizationContext());

            this.working = true;
            this.sendButton.IsEnabled = false;
            this.sendingLabel.Visibility = Visibility.Visible;
        }
Ejemplo n.º 5
0
 public SmtpClient(SmtpSession session)
 {
     this.session = session;
 }