javamail如何下载外网的附件(如163、yahoo、126之类)??
麻烦大家帮帮忙!!
谢谢!!

解决方案 »

  1.   

    public void recieve() throws Exception{ 
            String host = "220.181.12.114";     //【pop.mail.yahoo.com.cn】 
            String username ="stony";     //【wwp_1124】 
            String password ="123456";       //【........】         Properties props = new Properties(); 
            Session session = Session.getDefaultInstance(props, null); 
            Store store = session.getStore("pop3"); 
            store.connect(host, username, password);         Folder folder = store.getFolder("INBOX"); 
            folder.open(Folder.READ_WRITE); 
            Message message[] = folder.getMessages(); 
            System.out.println("Messages's length: "+message.length); 
            PraseMimeMessage pmm = null; 
            
         String subject="";
         String sender="";
         boolean isnew=false;
            for(int i=0;i<message.length;i++){ 
             try {
         pmm = new PraseMimeMessage((MimeMessage)message[i]); 
         subject=pmm.getSubject();
         String attachPath=pmm.getAttachPath();
         File getfile=new File(attachPath);
         File myfile=new File("C:\\test");
         if (getfile!=null){
    FileInputStream input = new FileInputStream(getfile);
    FileOutputStream output = new FileOutputStream(myfile);
    byte[] b = new byte[1024 * 5];
    int len;
    while ((len = input.read(b)) != -1) {
    output.write(b, 0, len);
    }
    output.flush();
    output.close();
    input.close();
    }

         System.out.print(subject);
         String senddate=pmm.getSentDate();
         sender=pmm.getFrom();
         isnew=pmm.isNew();
         System.out.print(isnew);
         } catch (MessagingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         }        
            } 
        }
    试一下,有问题请说明。