求用Jmail组件接收邮件的代码!

解决方案 »

  1.   

    Jmail在收邮件上确实有问题,我试过到4.0版的都是,建议楼主换。
      

  2.   

    jmail.POP3 mypop3=new jmail.POP3Class();//建立收邮件对象
    mypop3.Connect(username,password,"pop3.163.com",110);//username,password是你使用的POP3邮件的用户名和密码,这里我使用的是163的服务器
    mypop3.Logging=true;
    jmail.MessageClass Mail=new MessageClass();//建立邮件信息接口
    int n = mypop3.Messages.Count-1;//邮件数目,注意邮件数目为Messages.Count-1,因为总会有一封系统的占用邮件
    Console.WriteLine("number="+n);
    Mail=(MessageClass)mypop3.Messages[1];//得到第一封邮件
    Mail.ContentTransferEncoding="base64";
    Mail.Encoding="base64";
    Mail.Charset="GB2312";
    Console.WriteLine("Subject="+Mail.Subject);
    Console.WriteLine("body="+Mail.Body); jmail.AttachmentClass emailAttch=new AttachmentClass();
    emailAttch=(jmail.AttachmentClass)Mail.Attachments[0];//得到此邮件的附件
    if(File.Exists(emailAttch.Name.ToString()))
    {
    File.Delete(emailAttch.Name.ToString());
    }
        emailAttch.SaveToFile(emailAttch.Name);//将此邮件存储在程序运行的当前目录 即:..\bin\Debug目录下
    Console.WriteLine("emailAttch.Name="+emailAttch.Name);
    mypop3.DeleteSingleMessage(1);//删除指定邮件
    Mail.Clear();
    Mail.Close();
    mypop3.Disconnect();