Form1.cs
上传用户:jsz11269
上传日期:2017-01-14
资源大小:450k
文件大小:2k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Net.Mail;
- namespace SoketEmail
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void btnCheck_Click(object sender, EventArgs e)
- {
-
- if (tbServer.Text==""||tbUserName.Text=="")
- {
- MessageBox.Show("请输入服务器和用户名!");
- return;
- }
- POP3 p = new POP3(tbServer.Text, tbUserName.Text, tbPass.Text);
- int n = p.GetNumberOfNewMessages();
- if (n == -1)
- {
- MessageBox.Show("服务器连接错误");
- return;
- }
- for (int i = 1; i <=n; i++)
- // for (int i = 1; i <= 2; i++)
- {
- MailMessage msg = p.GetNewMessages(i - 1);
- if (msg != null)
- {
- ListViewItem lvi = new ListViewItem(i.ToString());
- lvi.SubItems.Add(msg.Subject);
- lvEmail.Items.Add(lvi);
- }
- }
-
- }
- private void lvEmail_SelectedIndexChanged(object sender, EventArgs e)
- {
- POP3 p = new POP3(tbServer.Text, tbUserName.Text, tbPass.Text);
- int i = lvEmail.SelectedItems.Count;
- if (i > 0)
- {
- MailMessage msg = p.GetNewMessages(lvEmail.SelectedItems[0].Index);
- if (msg != null)
- {
- //tbBody.AddHTML(msg.Body)
- tbBody.Text = msg.Body;
- tbSubject.Text = msg.Subject;
- tbSender.Text = msg.From.ToString();
- }
- }
- }
- }
- }