日期:2014-05-20 浏览次数:20803 次
//收 Aspose.Network.Pop3.Pop3Client pc = new Aspose.Network.Pop3.Pop3Client(); pc.Host = "pop.163.com"; pc.Username = "xxx@163.com"; pc.Password = "xxx"; pc.Connect(); pc.Login(); pc.SaveMessage(1,@"c:\1.eml");
------解决方案--------------------
应该需要别的Library
Framework默认只能发邮件,不能接收
------解决方案--------------------
public void ReceiveMails(string Username)
...{
jmail.Message Msg=new jmail.Message();
jmail.POP3 jpop = new jmail.POP3();
jmail.Attachments atts;
jmail.Attachment att;
//username为用户名,该方法通过用户名获取该用户的pop设置,即用户的POP用户名,密码,POP服务器地址以及端口号这四个参数,这四个参数是连接POP服务器的必用参数.
SqlDataReader dataReader = this.ExtGetSetting(Username);
if(dataReader.Read())
...{
if(dataReader["PopServer"].ToString()!=""&&dataReader["PopUsername"].ToString()!="")
...{
//连接POP服务器
jpop.Connect(dataReader["PopUsername"].ToString(),dataReader["PopPassword"].ToString(),dataReader["PopServer"].ToString(),Int32.Parse(dataReader["PopPort"].ToString()));
//如果服务器上有邮件
if(jpop.Count>=1)
...{
for(int i=1;i <=jpop.Count;i++)
...{
Msg = jpop.Messages[i];
atts=Msg.Attachments;
//取数据库中邮件信息中的最大发送时间,即最近接收到的一封邮件的时间
Database dbase=new Database();
DataTable data=dbase.GetDataTable("select max(MailSendDate) as MailSenderDate from TabMailList where MailTypeFlag='1'
if(Msg.Date>Convert.ToDateTime(data.Rows[0][0].ToString()))
...{
//将这封新邮件的信息保存到数据库
this.SaveExtMail(Msg,Username,dataReader["Email"].ToString(),jpop.GetMessageUID(i));
//获取附件上传到服务器并且将信息存入数据库
if(atts.Count>=1)
...{
for(int k=0;k <atts.Count;k++)
...{
att=atts[k];//获得附件
string attname=att.Name;
try
...{
Random TempNameInt = new Random();
string NewMailDirName = TempNameInt.Next(100000000).ToString();
Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(".")+"AttachFiles"+Username+""+NewMailDirName);
string mailPath="AttachFiles"+Username+""+NewMailDirName+""+attname;
att.SaveToFile(System.Web.HttpContext.Current.Server.MapPath(".")+mailPath);