!!在线等!!邮件!!解答正确马上结现!!进者有分!! http://blog.csdn.net/bromon/archive/2004/06/22/22646.aspx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 虽然是Java代码,不过转过来应该不困难。微软还有个叫JUMP的软件专门用来将Java代码转为C#的。 C#读取POP3邮件的操作 using System.Net.Sockets; using System.IO; using System.Net; using System;class POP { string POPServer; string user; string pwd; public POP(){} public POP(string server, string _user, string _pwd) { POPServer = server; user = _user; pwd = _pwd; } private NetworkStream Connect() { TcpClient sender = new TcpClient(POPServer,110); Byte[] outbytes; string input; NetworkStream ns = null; try { ns = sender.GetStream(); StreamReader sr = new StreamReader(ns); Console.WriteLine(sr.ReadLine() ); input = "user " + user + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length) ; Console.WriteLine(sr.ReadLine() ); input = "pass " + pwd + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length) ; Console.WriteLine(sr.ReadLine() ); return ns; } catch(InvalidOperationException) { Console.WriteLine("Could not connect to mail server"); return ns; } } public int GetNumberOfNewMessages() { Byte[] outbytes; string input; try { NetworkStream ns = Connect(); StreamReader sr = new StreamReader(ns); input = "stat" + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); string resp = sr.ReadLine(); Console.WriteLine(resp); //string[] tokens = resp.Split(new Char[] {" "}); string[] tokens = resp.Split(Convert.ToChar(" ")); input = "quit" + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); Console.WriteLine(sr.ReadLine()); sr.Close(); ns.Close(); return Convert.ToInt32(tokens[1]); } catch(InvalidOperationException) { Console.WriteLine("Could not connect to mail server"); return 0; } } public static void Main() { string sUserName; string sPop3; string sPass; Console.Write("请输入POP3地址:"); sPop3 = Console.ReadLine(); Console.Write("\r\n请输入用户名:"); sUserName = Console.ReadLine(); Console.Write("\r\n请输入登录密码:"); sPass = Console.ReadLine(); POP pop = new POP(sPop3,sUserName,sPass); Console.Write("New Messages = {0}", pop.GetNumberOfNewMessages() ); Console.ReadLine(); } } 你干嘛要自己写这么复杂的东西用jmail组件几个属性一设就妥了啊 如果你是想要读出附件的话,请先用截取字符串的方式读出来。再经过base64转换,应该能达到你想要的效果。祝你工作顺心!写完以后,告诉我一声! 发送时间: Tue, 9 Nov 2004 09发送者: "=?gb2312?B?bGlmZWk=?=" <[email protected]>接收者: "lifei9859" <[email protected]>主题: =?gb2312?B?dGVzdA==?=内容:--Boundary-=_CkANGvdWPtKDoQmZDaIaEkxkOTxvContent-Type: Multipart/Alternative; boundary="Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTx"--Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTxContent-Type: text/plain; charset="gb2312"Content-Transfer-Encoding: base64dGVzdA==--Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTxContent-Type: text/html; charset="gb2312"Content-Transfer-Encoding: base64dGVzdDxicj48YnI+IDxmb250IHN0eWxlPSJmb250c2l6ZToxNC44cHgiPi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tPGJyPgo8YSBocmVmPSJodHRwOi8vbWFpbC4xMjYuY29tL2V2ZW50L25ld3MyZy5odG0iIHRhcmdldD1fYmxhbms+w+K30dPKz+TIq8PmvfjI67OsIkciyrG0+iDN+NLX1Nm6tNbQzsTTys/ksNTW97XYzrs8L2E+Cg==--Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTx----Boundary-=_CkANGvdWPtKDoQmZDaIaEkxkOTxvContent-Type: text/plain; name="=?gb2312?B?MS50eHQ=?="Content-Transfer-Encoding: base64Content-Disposition: attachment; filename="=?gb2312?B?MS50eHQ=?="dGVzdA==--Boundary-=_CkANGvdWPtKDoQmZDaIaEkxkOTxv--如何将邮件的主体和附件分开,分别保存,,,,,,, C#读取POP3邮件的操作 using System.Net.Sockets; using System.IO; using System.Net; using System;class POP { string POPServer; string user; string pwd; public POP(){} public POP(string server, string _user, string _pwd) { POPServer = server; user = _user; pwd = _pwd; } private NetworkStream Connect() { TcpClient sender = new TcpClient(POPServer,110); Byte[] outbytes; string input; NetworkStream ns = null; try { ns = sender.GetStream(); StreamReader sr = new StreamReader(ns); Console.WriteLine(sr.ReadLine() ); input = "user " + user + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length) ; Console.WriteLine(sr.ReadLine() ); input = "pass " + pwd + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length) ; Console.WriteLine(sr.ReadLine() ); return ns; } catch(InvalidOperationException) { Console.WriteLine("Could not connect to mail server"); return ns; } } public int GetNumberOfNewMessages() { Byte[] outbytes; string input; try { NetworkStream ns = Connect(); StreamReader sr = new StreamReader(ns); input = "stat" + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); string resp = sr.ReadLine(); Console.WriteLine(resp); //string[] tokens = resp.Split(new Char[] {" "}); string[] tokens = resp.Split(Convert.ToChar(" ")); input = "quit" + "\r\n"; outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray()); ns.Write(outbytes,0,outbytes.Length); Console.WriteLine(sr.ReadLine()); sr.Close(); ns.Close(); return Convert.ToInt32(tokens[1]); } catch(InvalidOperationException) { Console.WriteLine("Could not connect to mail server"); return 0; } } public static void Main() { string sUserName; string sPop3; string sPass; Console.Write("请输入POP3地址:"); sPop3 = Console.ReadLine(); Console.Write("\r\n请输入用户名:"); sUserName = Console.ReadLine(); Console.Write("\r\n请输入登录密码:"); sPass = Console.ReadLine(); POP pop = new POP(sPop3,sUserName,sPass); Console.Write("New Messages = {0}", pop.GetNumberOfNewMessages() ); Console.ReadLine(); } } ---------------------------------------------------------感谢这么多支持的朋友,用POP收取邮件,我已经全部收取下来,只是附件无法取出,请哪位高手指点一下的,另外,附件格式不同会有不同的操作方法吗?--------------------------------------------------------- 求助,没用接触过C#,但是工作需要做一个修改,求助!!!! vpn拨号连接 求问如何通过C#实现ADSL重拨? 关于委托的初级问题 C#操作修改数据库字段类型 有对c# XtraGrid suite控件包熟悉的吗?用过的请进来指点指点。 如何通过程序过滤到网页html中的广告? NHibernate 的分页问题? 用C#如何做个像QQ空间相册那样的相册啊 在线!怎样实现类似CSDN论谈左边滚动条,和可以拖动TreeView的宽度呢?? 關於CONTINUE問題 有没有在 WINDOWS 环境下 FORTRAN 的编译器?
微软还有个叫JUMP的软件专门用来将Java代码转为C#的。
using System.Net.Sockets;
using System.IO;
using System.Net;
using System;class POP
{
string POPServer;
string user;
string pwd;
public POP(){}
public POP(string server, string _user, string _pwd)
{
POPServer = server;
user = _user;
pwd = _pwd;
}
private NetworkStream Connect()
{
TcpClient sender = new TcpClient(POPServer,110);
Byte[] outbytes;
string input;
NetworkStream ns = null;
try
{
ns = sender.GetStream();
StreamReader sr = new StreamReader(ns);
Console.WriteLine(sr.ReadLine() ); input = "user " + user + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length) ;
Console.WriteLine(sr.ReadLine() ); input = "pass " + pwd + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length) ;
Console.WriteLine(sr.ReadLine() ); return ns;
}
catch(InvalidOperationException)
{
Console.WriteLine("Could not connect to mail server");
return ns;
}
}
public int GetNumberOfNewMessages()
{
Byte[] outbytes;
string input;
try
{
NetworkStream ns = Connect();
StreamReader sr = new StreamReader(ns); input = "stat" + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
string resp = sr.ReadLine();
Console.WriteLine(resp);
//string[] tokens = resp.Split(new Char[] {" "});
string[] tokens = resp.Split(Convert.ToChar(" ")); input = "quit" + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
Console.WriteLine(sr.ReadLine()); sr.Close();
ns.Close();
return Convert.ToInt32(tokens[1]);
}
catch(InvalidOperationException)
{
Console.WriteLine("Could not connect to mail server");
return 0;
}
}
public static void Main()
{
string sUserName;
string sPop3;
string sPass;
Console.Write("请输入POP3地址:");
sPop3 = Console.ReadLine();
Console.Write("\r\n请输入用户名:");
sUserName = Console.ReadLine();
Console.Write("\r\n请输入登录密码:");
sPass = Console.ReadLine();
POP pop = new POP(sPop3,sUserName,sPass);
Console.Write("New Messages = {0}", pop.GetNumberOfNewMessages() );
Console.ReadLine();
}
}
用jmail组件几个属性一设就妥了啊
祝你工作顺心!
写完以后,告诉我一声!
发送者: "=?gb2312?B?bGlmZWk=?=" <[email protected]>
接收者: "lifei9859" <[email protected]>
主题: =?gb2312?B?dGVzdA==?=
内容:--Boundary-=_CkANGvdWPtKDoQmZDaIaEkxkOTxvContent-Type: Multipart/Alternati
ve; boundary="Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTx"--Boundary-1=_CkANGvdWPtKD
oQmZDaIaEkxkOTxContent-Type: text/plain; charset="gb2312"Content-Transfer-Encodi
ng: base64dGVzdA==--Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTxContent-Type: text/ht
ml; charset="gb2312"Content-Transfer-Encoding: base64dGVzdDxicj48YnI+IDxmb250IHN
0eWxlPSJmb250c2l6ZToxNC44cHgiPi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0
tLS0tLS0tLS0tLS0tLS0tLS0tLS0tPGJyPgo8YSBocmVmPSJodHRwOi8vbWFpbC4xMjYuY29tL2V2ZW5
0L25ld3MyZy5odG0iIHRhcmdldD1fYmxhbms+w+K30dPKz+TIq8PmvfjI67OsIkciyrG0+iDN+NLX1Nm
6tNbQzsTTys/ksNTW97XYzrs8L2E+Cg==--Boundary-1=_CkANGvdWPtKDoQmZDaIaEkxkOTx----Bo
undary-=_CkANGvdWPtKDoQmZDaIaEkxkOTxvContent-Type: text/plain; name="=?gb2312?B?
MS50eHQ=?="Content-Transfer-Encoding: base64Content-Disposition: attachment; fil
ename="=?gb2312?B?MS50eHQ=?="dGVzdA==--Boundary-=_CkANGvdWPtKDoQmZDaIaEkxkOTxv--
如何将邮件的主体和附件分开,分别保存,,,,,,,
using System.Net.Sockets;
using System.IO;
using System.Net;
using System;class POP
{
string POPServer;
string user;
string pwd;
public POP(){}
public POP(string server, string _user, string _pwd)
{
POPServer = server;
user = _user;
pwd = _pwd;
}
private NetworkStream Connect()
{
TcpClient sender = new TcpClient(POPServer,110);
Byte[] outbytes;
string input;
NetworkStream ns = null;
try
{
ns = sender.GetStream();
StreamReader sr = new StreamReader(ns);
Console.WriteLine(sr.ReadLine() ); input = "user " + user + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length) ;
Console.WriteLine(sr.ReadLine() ); input = "pass " + pwd + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length) ;
Console.WriteLine(sr.ReadLine() ); return ns;
}
catch(InvalidOperationException)
{
Console.WriteLine("Could not connect to mail server");
return ns;
}
}
public int GetNumberOfNewMessages()
{
Byte[] outbytes;
string input;
try
{
NetworkStream ns = Connect();
StreamReader sr = new StreamReader(ns); input = "stat" + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
string resp = sr.ReadLine();
Console.WriteLine(resp);
//string[] tokens = resp.Split(new Char[] {" "});
string[] tokens = resp.Split(Convert.ToChar(" ")); input = "quit" + "\r\n";
outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
Console.WriteLine(sr.ReadLine()); sr.Close();
ns.Close();
return Convert.ToInt32(tokens[1]);
}
catch(InvalidOperationException)
{
Console.WriteLine("Could not connect to mail server");
return 0;
}
}
public static void Main()
{
string sUserName;
string sPop3;
string sPass;
Console.Write("请输入POP3地址:");
sPop3 = Console.ReadLine();
Console.Write("\r\n请输入用户名:");
sUserName = Console.ReadLine();
Console.Write("\r\n请输入登录密码:");
sPass = Console.ReadLine();
POP pop = new POP(sPop3,sUserName,sPass);
Console.Write("New Messages = {0}", pop.GetNumberOfNewMessages() );
Console.ReadLine();
}
}