C# Builder 实现POP3信箱的监视__教程 |
|
日期:2007-5-20 1:21:23 人气:178 [大 中 小] |
|
|
|
{ if(Height > 3) { this.Height -= 3; this.Location = new Point(this.Location.X, this.Location.Y + 3); } else { this.timer3.Enabled = false; this.Close(); } }
private void timer1_Tick(object sender, System.EventArgs e) { ScrollUp(); }
private void timer2_Tick(object sender, System.EventArgs e) { timer2.Enabled = false; timer3.Enabled = true; }
private void timer3_Tick(object sender, System.EventArgs e) { ScrollDown(); }
public void ScrollShow() { this.Width = 194; this.Height = 0; this.Show(); this.timer1.Enabled = true; }
private void WinForm1_Activated(object sender, System.EventArgs e) { linkLabel1.Text="您有"+str_num+"封新邮件!"; }
} } 具体的实现,可以参考一下网上的一篇文章:《用VC#编写仿MSN Messager的滚动提示窗口》,已经记不清出处了,可以通过这个网http://yousoft.hi.com.cn/article_view.asp?id=6595浏览。
3.获取邮件数量的实现,代码见下: 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"+"A:"+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"+"B:"+sr.ReadLine(); } catch(InvalidOperationException ioe){ tB_status.Text="Could not connect to mail server"; }
if (str_num!="") { WinForm1 form = new WinForm1(); form.str_num=str_num; form.ScrollShow(); } 程序与邮件服务器建立一个TCP连接,然后发送POP3的一些命令,取到服务器传回的信息,得到邮件的数量。 STAT命令的回应中有两个数字,分别表示邮件的数量和邮件的大小。一般格式是这样的“+OK 数量 大小” 所以,只要根据服务器返回的信息,提取+OK,然后再按空格分隔得到数量。代码见上。
4.注册表的读写: 我们知道,要实现程序在开机后自己运行,可以通过写注册表HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run实现 另外,为了方便用户,我们把邮件服务器,用户,密码等信息存入注册表,不用每次都再输一次。 保存信息代码如下: RegistryKey rk; Registry.CurrentUser.CreateSubKey("Software\\yousoft"); |
|
出处:本站原创 作者:佚名 |
|
|