// Helping methods for Pop3 Client user Interface private void ReceiveEmails() { try { Pop3Client pop_client = new Pop3Client(); pop_client.Pop3Server = this.PopServer.Text; pop_client.Pop3Port = Convert.ToInt32(this.PopPort.Text); pop_client.UserName = this.PopUserName.Text; pop_client.Password = this.PopPassword.Text; this.EnableDisableConnectButton(false); pop_client.ConnectionEstablishing += new ConnectEventHandler(this.pop_ConnectionEstablishing); pop_client.ConnectionEstablished += new ConnectEventHandler(this.pop_ConnectionEstablished); pop_client.AuthenticationBegan += new AuthenticateEventHandler(this.pop_AuthenticationBegan); pop_client.AuthenticationFinished += new AuthenticateEventHandler(this.pop_AuthenticationFinished); pop_client.StartedDataReceiving += new DataReceivingEventHandler(this.pop_StartedDataReceiving); pop_client.EndedDataReceiving += new DataReceivingEventHandler(this.pop_EndedDataReceiving); pop_client.Disconnected += new DisconnectEventHandler(this.pop_Disconnected); this.pop = pop_client; pop_client.Connect(); this.EnableDisableDisconnectButton(true); pop_client.GetMailBoxDetails(); //it sets the TotalEmails and TotalEmailSize properties if (pop_client.TotalEmails >= 1) { this.UpdateStatusBar("Retrieving Emails"); this.FillInboxListView(pop_client); this.UpdateStatusBar("Email Client"); } else { this.UpdateStatusBar("Email Client"); MessageBox.Show(this, "No email message exists in the inbox!.", "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (SmtpClientException err) { MessageBox.Show(this, err.ErrorMessage, "Email Client", MessageBoxButtons.OK, MessageBoxIcon.Error); this.UpdateStatusBar("Email Client"); this.EnableDisableConnectButton(true); this.EnableDisableDisconnectButton(false); } }
private void FillInboxListView(Pop3Client obj) { ArrayList sender = new ArrayList(); ArrayList subject = new ArrayList(); ArrayList date = new ArrayList(); ArrayList size = new ArrayList(); DateTime date_time; string temp = ""; this.MailMessages.Items.Clear(); for (int i = 1; i <= obj.TotalEmails; i++) { string emailHeader = obj.FetchEmailTop(i, 0); sender.Add(obj.From); subject.Add(obj.Subject); try { date_time = DateTime.Parse(obj.Date); temp = date_time.ToString("D"); date.Add(temp); } catch(Exception) { date.Add(obj.Date); } size.Add(obj.GetMailSize(i)); } for (int j = 0; j < sender.Count; j++) { ListViewItem item = new ListViewItem(); item.Text = sender[j].ToString(); item.SubItems.Add(subject[j].ToString()); item.SubItems.Add(date[j].ToString()); item.SubItems.Add(size[j].ToString()); this.InsertItem(item); } }