www.pudn.com > mailreveive.rar > Form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Pop3Com;
namespace MailNotifier
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox host;
private System.Windows.Forms.TextBox port;
private System.Windows.Forms.TextBox username;
private System.Windows.Forms.TextBox password;
private System.Windows.Forms.Button checkBtn;
private System.Windows.Forms.StatusBar statusBar;
private Pop3 mailer;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.host = new System.Windows.Forms.TextBox();
this.port = new System.Windows.Forms.TextBox();
this.username = new System.Windows.Forms.TextBox();
this.password = new System.Windows.Forms.TextBox();
this.checkBtn = new System.Windows.Forms.Button();
this.statusBar = new System.Windows.Forms.StatusBar();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(104, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Pop3服务器地址:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 23);
this.label2.TabIndex = 1;
this.label2.Text = "端口号:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(32, 90);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 23);
this.label3.TabIndex = 2;
this.label3.Text = "用户名:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label4
//
this.label4.Location = new System.Drawing.Point(32, 127);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 23);
this.label4.TabIndex = 3;
this.label4.Text = "密码:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// host
//
this.host.Location = new System.Drawing.Point(120, 16);
this.host.Name = "host";
this.host.Size = new System.Drawing.Size(168, 21);
this.host.TabIndex = 4;
this.host.Text = "";
//
// port
//
this.port.Location = new System.Drawing.Point(120, 53);
this.port.Name = "port";
this.port.Size = new System.Drawing.Size(168, 21);
this.port.TabIndex = 5;
this.port.Text = "110";
//
// username
//
this.username.Location = new System.Drawing.Point(120, 90);
this.username.Name = "username";
this.username.Size = new System.Drawing.Size(168, 21);
this.username.TabIndex = 6;
this.username.Text = "";
//
// password
//
this.password.Location = new System.Drawing.Point(120, 127);
this.password.Name = "password";
this.password.PasswordChar = '*';
this.password.Size = new System.Drawing.Size(168, 21);
this.password.TabIndex = 7;
this.password.Text = "";
//
// checkBtn
//
this.checkBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.checkBtn.Location = new System.Drawing.Point(208, 176);
this.checkBtn.Name = "checkBtn";
this.checkBtn.Size = new System.Drawing.Size(75, 24);
this.checkBtn.TabIndex = 8;
this.checkBtn.Text = "开始检查";
this.checkBtn.Click += new System.EventHandler(this.checkBtn_Click);
//
// statusBar
//
this.statusBar.Location = new System.Drawing.Point(0, 223);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(304, 22);
this.statusBar.TabIndex = 9;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(304, 245);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.statusBar,
this.checkBtn,
this.password,
this.username,
this.port,
this.host,
this.label4,
this.label3,
this.label2,
this.label1});
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MailNotifier 1.0";
this.ResumeLayout(false);
}
#endregion
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void checkBtn_Click(object sender, System.EventArgs e)
{
// 正确性检查
if(host == null || host.Text.Trim().Length == 0)
{
MessageBox.Show("请填入服务器地址!");
}
else
if(username == null || username.Text.Trim().Length == 0)
{
MessageBox.Show("请填入用户名!");
}
else
if(password == null || password.Text.Trim().Length == 0)
{
MessageBox.Show("请填入密码!");
}
else
{
mailer = new Pop3();
mailer.Host = host.Text;
mailer.Port = Int32.Parse(port.Text);
mailer.UserName = username.Text;
mailer.PassWord = password.Text;
statusBar.Text = "正在接收信息……";
mailer.OnMailReceived += new Pop3.MailReceivedDelegate(OnMailReceived);
mailer.ReceiveMessageAsync();
}
}
private void OnMailReceived()
{
statusBar.Text = "邮件接收完毕!";
MessageBox.Show("你有" + mailer.NumOfMails.ToString() + "个邮件!","信息",
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}