private void _bRetrieveMessage_Click(object sender, EventArgs e)
        {
            // We instantiate the pop3 client.
            Pop3Client pop = new Pop3Client();

            try
            {
                this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text));

                // Connect to the pop3 client
                pop.APOPConnect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);

                if (pop.MessageCount > 0)
                {
                    //Retrive a message at a particulat index (index 1 in this sample)
                    ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1);

                    this.AddLogEntry(string.Format("Subject: {0} From :{1} Message Body {2}"
                                                   , message.Subject, message.From.Email, message.BodyText));
                }

                else
                {
                    this.AddLogEntry("There is no message in this pop3 account");
                }
            }

            catch (Pop3Exception pexp)
            {
                this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (pop.IsConnected)
                {
                    pop.Disconnect();
                }
            }
        }
Exemple #2
0
        private void btnClick_Click(object sender, EventArgs e)
        {
            ToggleMyStatus(this);//Enable
            try
            {
                Pop3Client client = new Pop3Client();
                if (chkAPOP.Checked)
                {
                    client.APOPConnect(txtHost.Text, txtUser.Text, txtPassword.Text);
                }
                else
                {
                    client.Connect(txtHost.Text, txtUser.Text, txtPassword.Text);
                }

                if (client.MessageCount == 0)
                {
                    client.Disconnect();
                    Sleep();
                    MessageBox.Show("You do not have any new messages");
                }
                else
                {
                    //Load up, POP3Result.
                    //Pass up Pop3Client, for further operations
                    Pop3Result result = new Pop3Result();
                    result.Pop = client;
                    result.ShowDialog();
                    client.Disconnect();
                    Sleep();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            ToggleMyStatus(this);//Disable
        }