Form1.cs
上传用户:jsz11269
上传日期:2017-01-14
资源大小:450k
文件大小:2k
源码类别:

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Net.Mail;
  9. namespace SoketEmail
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.         }
  20.         private void btnCheck_Click(object sender, EventArgs e)
  21.         {
  22.            
  23.             if (tbServer.Text==""||tbUserName.Text=="")
  24.             {
  25.                 MessageBox.Show("请输入服务器和用户名!");
  26.                 return;
  27.             }
  28.             POP3 p = new POP3(tbServer.Text, tbUserName.Text, tbPass.Text);
  29.             int n = p.GetNumberOfNewMessages();
  30.             if (n == -1)
  31.             {
  32.                 MessageBox.Show("服务器连接错误");
  33.                 return;
  34.             }
  35.            for (int i = 1; i <=n; i++)
  36.            // for (int i = 1; i <= 2; i++)
  37.             {
  38.                 MailMessage msg = p.GetNewMessages(i - 1);
  39.                 if (msg != null)
  40.                 {
  41.                     ListViewItem lvi = new ListViewItem(i.ToString());
  42.                     lvi.SubItems.Add(msg.Subject);
  43.                     lvEmail.Items.Add(lvi);
  44.                 }
  45.             }
  46.           
  47.         }
  48.         private void lvEmail_SelectedIndexChanged(object sender, EventArgs e)
  49.         {
  50.             POP3 p = new POP3(tbServer.Text, tbUserName.Text, tbPass.Text);
  51.             int i = lvEmail.SelectedItems.Count;
  52.             if (i > 0)
  53.             {
  54.                 MailMessage msg = p.GetNewMessages(lvEmail.SelectedItems[0].Index);
  55.                 if (msg != null)
  56.                 {
  57.                     //tbBody.AddHTML(msg.Body)
  58.                     tbBody.Text = msg.Body;
  59.                     tbSubject.Text = msg.Subject;
  60.                     tbSender.Text = msg.From.ToString();
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }