| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 636 人关注过本帖
标题:[求助]C# Builder实现POP3信箱的监视
只看楼主 加入收藏
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
结帖率:25%
收藏
 问题点数:0 回复次数:0 
[求助]C# Builder实现POP3信箱的监视

帮我看看错误怎么改.谢谢了先! using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net.Sockets; using System.IO; using System.Net; using Microsoft.Win32;

namespace pop3 { /// <summary> /// Summary description for WinForm. /// </summary> public class WinForm : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox tB_server; private System.Windows.Forms.TextBox tB_user; private System.Windows.Forms.TextBox tB_pwd; private System.Windows.Forms.TextBox tB_status; private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private bool f_open=true; private string str_num=""; private System.Windows.Forms.Button button2; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.TextBox tB_mins; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Button button3; private System.Windows.Forms.CheckBox cB_autorun;

public WinForm() { // // Required for Windows Form Designer support // InitializeComponent();

// // TOD Add any constructor code after InitializeComponent call // }

/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose (bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); }

#region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WinForm)); this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.tB_server = new System.Windows.Forms.TextBox(); this.tB_user = new System.Windows.Forms.TextBox(); this.tB_pwd = new System.Windows.Forms.TextBox(); this.tB_status = new System.Windows.Forms.TextBox(); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.button2 = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.tB_mins = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.button3 = new System.Windows.Forms.Button(); this.cB_autorun = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(152, 176); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "取邮件"; this.button1.Click += new System.EventHandler(this.button1_Click); // // label1 // this.label1.Location = new System.Drawing.Point(24, 32); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(80, 23); this.label1.TabIndex = 1; this.label1.Text = "邮件服务器:"; // // label2 // this.label2.Location = new System.Drawing.Point(48, 64); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(56, 23); this.label2.TabIndex = 2; this.label2.Text = "用户名:"; // // label3 // this.label3.Location = new System.Drawing.Point(58, 96); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(48, 23); this.label3.TabIndex = 3; this.label3.Text = "密码:"; // // tB_server // this.tB_server.Location = new System.Drawing.Point(112, 24); this.tB_server.Name = "tB_server"; this.tB_server.Size = new System.Drawing.Size(176, 21); this.tB_server.TabIndex = 4; this.tB_server.Text = ""; this.tB_server.TextChanged += new System.EventHandler(this.tB_pwd_TextChanged); // // tB_user // this.tB_user.Location = new System.Drawing.Point(112, 60); this.tB_user.Name = "tB_user"; this.tB_user.Size = new System.Drawing.Size(176, 21); this.tB_user.TabIndex = 5; this.tB_user.Text = ""; this.tB_user.TextChanged += new System.EventHandler(this.tB_pwd_TextChanged); // // tB_pwd // this.tB_pwd.Location = new System.Drawing.Point(112, 91); this.tB_pwd.Name = "tB_pwd"; this.tB_pwd.PasswordChar = '*'; this.tB_pwd.Size = new System.Drawing.Size(176, 21); this.tB_pwd.TabIndex = 6; this.tB_pwd.Text = ""; this.tB_pwd.TextChanged += new System.EventHandler(this.tB_pwd_TextChanged); // // tB_status // this.tB_status.Location = new System.Drawing.Point(16, 208); this.tB_status.Multiline = true; this.tB_status.Name = "tB_status"; this.tB_status.Size = new System.Drawing.Size(328, 80); this.tB_status.TabIndex = 7; this.tB_status.Text = ""; // // notifyIcon1 // this.notifyIcon1.ContextMenu = this.contextMenu1; this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon"))); this.notifyIcon1.Text = "邮件检测"; this.notifyIcon1.Visible = true; // // contextMenu1 // this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem2, this.menuItem3}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.Text = "设置&S"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // menuItem2 // this.menuItem2.Index = 1; this.menuItem2.Text = "-"; // // menuItem3 // this.menuItem3.Index = 2; this.menuItem3.Text = "退出&Q"; this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); // // button2 // this.button2.Location = new System.Drawing.Point(48, 176); this.button2.Name = "button2"; this.button2.TabIndex = 8; this.button2.Text = "最小化"; this.button2.Click += new System.EventHandler(this.button2_Click); // // timer1 // this.timer1.Interval = 5000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // tB_mins // this.tB_mins.Location = new System.Drawing.Point(112, 124); this.tB_mins.Name = "tB_mins"; this.tB_mins.Size = new System.Drawing.Size(144, 21); this.tB_mins.TabIndex = 10; this.tB_mins.Text = "20000"; this.tB_mins.TextChanged += new System.EventHandler(this.tB_pwd_TextChanged); // // label4 // this.label4.Location = new System.Drawing.Point(32, 128); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(72, 23); this.label4.TabIndex = 9; this.label4.Text = "时间间隔:"; // // label5 // this.label5.Location = new System.Drawing.Point(264, 129); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(40, 16); this.label5.TabIndex = 11; this.label5.Text = "毫秒"; // // button3 // this.button3.Location = new System.Drawing.Point(264, 176); this.button3.Name = "button3"; this.button3.TabIndex = 12; this.button3.Text = "应用"; this.button3.Click += new System.EventHandler(this.button3_Click); // // cB_autorun // this.cB_autorun.Location = new System.Drawing.Point(112, 152); this.cB_autorun.Name = "cB_autorun"; this.cB_autorun.Size = new System.Drawing.Size(160, 24); this.cB_autorun.TabIndex = 13; this.cB_autorun.Text = "启动时自动执行"; // // WinForm // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(368, 301); this.Controls.Add(this.cB_autorun); this.Controls.Add(this.button3); this.Controls.Add(this.label5); this.Controls.Add(this.tB_mins); this.Controls.Add(this.label4); this.Controls.Add(this.button2); this.Controls.Add(this.tB_status); this.Controls.Add(this.tB_pwd); this.Controls.Add(this.tB_user); this.Controls.Add(this.tB_server); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.MaximizeBox = false; this.Name = "WinForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "收取邮件"; this.Load += new System.EventHandler(this.WinForm_Load); this.Activated += new System.EventHandler(this.WinForm_Activated); this.ResumeLayout(false);

} #endregion

/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new WinForm()); }

private void button1_Click(object sender, System.EventArgs e) { string str_server; if ((tB_server.Text!="") && (tB_user.Text!="") && (tB_pwd.Text!="")) { TcpClient tcpc = new TcpClient(tB_server.Text,110); Byte[] outbytes; string input; NetworkStream ns = null; try { ns = tcpc.GetStream(); StreamReader sr = new StreamReader(ns); tB_status.Text=sr.ReadLine();

input = "USER " + tB_user.Text + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); tB_status.Text=tB_status.Text+"\r\n"+sr.ReadLine();

input = "PASS " + tB_pwd.Text + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); tB_status.Text=tB_status.Text+"\r\n"+sr.ReadLine();

input = "STAT" + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length) ; str_server=sr.ReadLine();

str_num=""; if (str_server.StartsWith("+OK")) { str_num=str_server.Split(' ')[1]; } else str_num="";

tB_status.Text=tB_status.Text+"\r\n"+str_server;

input = "QUIT" + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); tB_status.Text=tB_status.Text+"\r\n"+sr.ReadLine(); } catch(InvalidOperationException ioe) { tB_status.Text="Could not connect to mail server"; }

if (str_num!="") { WinForm form = new WinForm(); form.str_num=str_num; form.ScrollShow(); } } }

private void WinForm_Activated(object sender, System.EventArgs e) { if (f_open) { this.Hide(); f_open=false; } }

private void menuItem3_Click(object sender, System.EventArgs e) { this.Close(); }

private void menuItem1_Click(object sender, System.EventArgs e) { this.Show(); this.Focus(); }

private void button2_Click(object sender, System.EventArgs e) { this.Hide(); }

private void timer1_Tick(object sender, System.EventArgs e) { button1_Click(sender,e); }

private void tB_pwd_TextChanged(object sender, System.EventArgs e) { timer1.Enabled=false; if ((tB_server.Text!="") && (tB_user.Text!="") && (tB_pwd.Text!="")) { timer1.Interval=System.Convert.ToInt32(tB_mins.Text); timer1.Enabled=true; } else { timer1.Enabled=false; } }

private void button3_Click(object sender, System.EventArgs e) { RegistryKey rk; Registry.CurrentUser.CreateSubKey("Software\\yousoft"); rk=Registry.CurrentUser.OpenSubKey("Software\\yousoft",true); rk.SetValue("server",tB_server.Text); rk.SetValue("user",tB_user.Text); rk.SetValue("pwd",tB_pwd.Text); rk.SetValue("interval",tB_mins.Text);

if (cB_autorun.Checked) { rk=Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",true); rk.SetValue("chkmail",Application.ExecutablePath); } else { rk=Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",true); rk.DeleteValue("chkmail"); } rk.Close(); }

private void WinForm_Load(object sender, System.EventArgs e) { RegistryKey rk; rk=Registry.CurrentUser.OpenSubKey("Software\\yousoft",false); object srv=rk.GetValue("server"); if (srv!=null) tB_server.Text=srv.ToString(); object usr=rk.GetValue("user"); if (usr!=null) tB_user.Text=usr.ToString(); object pwd=rk.GetValue("pwd"); if (pwd!=null) tB_pwd.Text=pwd.ToString(); object mins=rk.GetValue("interval"); if (mins!=null) tB_mins.Text=mins.ToString(); rk.Close(); }

} }

搜索更多相关主题的帖子: 信箱 Builder 
2005-10-09 16:44
快速回复:[求助]C# Builder实现POP3信箱的监视
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028928 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved