当前位置:编程学习 > C#/ASP.NET >>

找到一份Jmail收邮件的代码,却看不懂,帮我看看啊,

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); 
                                                
                                                //获取该封邮件在数据库的ID,以便和附件信息相对应,取邮件表中的最大ID即可 
                                                int mailID=this.GetMailID();
                                               //将附件信息存入数据库
                                                this.AttExtSend(mailID,attname,att.Size,mailPath,Msg.From);
                                            }
                                            catch(Exception ex)
                                            {
                                                throw new Exception(ex.Message);
                                            }
                                        
                                        }
                                    }                                        
                                }                            
                            }                        
                        }    

                        //删除服务器上的邮件
                        jpop.DeleteMessages();
                        //断开连接    
                        jpop.Disconnect();
                    }
                
            }
        }
_____________________
以下几句怎么理解:
1\SqlDataReader dataReader = this.ExtGetSetting(Username);
2\Database dbase=new Database();
3\int mailID=this.GetMailID();
哪给朋友给我一份可以用的接收邮件的代码吧,搞了好久没搞定,谢谢! --------------------编程问答-------------------- 顶了,
1\SqlDataReader dataReader = this.ExtGetSetting(Username); 获取DataReader对象
2\Database dbase=new Database();实力话一个DB类
3\int mailID=this.GetMailID();  邮件的ID唯一性的
--------------------编程问答-------------------- 期待高人出现.... --------------------编程问答-------------------- 以下几句怎么理解:
1\SqlDataReader dataReader = this.ExtGetSetting(Username);//ExtGetSetting一个函数,返回一个SqlDataReader实例
2\Database dbase=new Database();//DataBase是一个类,估计是进行数据库操作的
3\int mailID=this.GetMailID();//一个整形,代表ID
哪给朋友给我一份可以用的接收邮件的代码吧,搞了好久没搞定,谢谢! --------------------编程问答-------------------- 一起学习一下
顶 --------------------编程问答-------------------- jmail.POP3Class popMail = new jmail.POP3Class();
        jmail.Message mailMessage;
        jmail.Attachments atts; //建立附件集接口
        jmail.Attachment att; //建立附件接口
        //try
        //{
        popMail.Connect(EUser, EPwd, "pop.163.com", 110);
        
            if (popMail.Count > 0)
            {
                
                for (int i = 1; i <= popMail.Count; i++)
                {
                    UID = popMail.GetMessageUID(i);//得到服务器上每封mail的UID                                              // 据此判断这封邮件是否是新邮件
                    int IfNew = objLogic.IfNewMail(UID);//在逻辑层写的一个函数判断数据库中是否有当前的UID
                    if (IfNew == 1)//如果不存在
                    {
                        mailMessage = popMail.Messages[i];
                        atts = mailMessage.Attachments;
                        mailMessage.Charset = "GB18030";
                        mailMessage.ISOEncodeHeaders = false;
                        From = mailMessage.From;
                        dtime = mailMessage.Date;
                        FromName = mailMessage.FromName;
                        Subject = mailMessage.Subject;
                        Body = mailMessage.Body;
                        #region 邮件大小的单位转换
                        string mSize = mailMessage.Size.ToString();
                        double imSize = Convert.ToDouble(mSize);
                        imSize *= 0.001;
                        string Size = Convert.ToString(imSize)+"KB";
                        #endregion // 邮件大小的单位转换
                        if (atts.Count == 0)
                        {
                            AppPath = "";
                        }
                        else
                        {
                            for (int j = 0; j < atts.Count; j++)
                            {
                                att = atts[j];
                                string attname = att.Name;
                                AppPath = "e:\\attFile\\" + attname;
                                try
                                {
                                    att.SaveToFile("e:\\attFile\\" + attname);
                                }
                                catch(Exception ex)
                                {
                                    
                                    File.Delete("e:\\attFile\\" + attname);
                                    att.SaveToFile("e:\\attFile\\" + attname);
                                }
                                
                            }
                        }
                        
                        att = null;
                        atts = null;
                        objLogic.InsertInBox(UID,Subject, Body, From, dtime, Size, AppPath, FromName);
                    }
                    
                }
                
            }
            //else
            //{
            //    Label1.Text = "没有新邮件!";
            //}
            //popMail.DeleteMessages();
            popMail.Disconnect();
            popMail = null;
        //}
        //catch
        //{
        //    Label1.Text = "请检测网络配置!";
        //}
            DataTable dt = new DataTable();
            dt = objLogic.SelectFromInbox();
            GridView1.DataSource = dt;
            GridView1.DataBind();
        
    } --------------------编程问答-------------------- 代码看不懂的地方
欢迎与我讨论  我的系统就可以实现这项功能 --------------------编程问答-------------------- 顶顶。
把邮件写到本地数据库保存。 --------------------编程问答-------------------- 我查了好多的关于jmail收取邮件的问题。给的代码都是和上面的代码一样。但是我自己调试的时候就老是抛异常“This function is not included in this version of jmail.”。我以为是我装的jmail版本太低了。我又在网上下载了最新的jmail。然后进行安装。再测试。但就是不成功。抛出异常的时候就是jpop.Connect(Euname,Epwd,server,port)这里。到底要怎样才可以啊?
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,