我照着书上的例子,但是查看不了收件箱啊,难道pop服务器不支持,只有imap支持?
package net;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;public class SecurePOP3Client extends javax.swing.JFrame {
    
    public SecurePOP3Client() {
        initComponents();
    }
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jhost = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u670d\u52a1\u5668");        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(174, 174, 174)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jhost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 311, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(295, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jhost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(97, 97, 97)
                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(314, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try {
            String host =jhost.getText();
            String provider = "pop3";
            Properties props=new Properties();
            Session session = Session.getDefaultInstance(props, 
       new MailAuthenticator());
      Store store = session.getStore(provider);
      store.connect(host, "用户名", "密码");
      
      // Open the folder
      Folder inbox = store.getFolder("INBOX");
      if (inbox == null) {
        System.out.println("No INBOX");
        System.exit(1);
      }  
      inbox.open(Folder.READ_ONLY);
      
      // Get the messages from the server
      Message[] messages = inbox.getMessages();
      for (int i = 0; i < messages.length; i++) {
        System.out.println("------------ Message " + (i+1) 
         + " ------------");
        messages[i].writeTo(System.out);
      }       // Close the connection 
      // but don't remove the messages from the server
      inbox.close(false);
      store.close();        } catch (NoSuchProviderException ex) {
            ex.printStackTrace();
        } catch (MessagingException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        
    }                                            public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SecurePOP3Client().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jhost;
    // End of variables declaration
    
}服务器我输入的是:pop.163.com,但是getMessages的数组长度为0没取到

解决方案 »

  1.   

    现在的163好像要自己创建POP帐号
      

  2.   

    to rickhunterchen:
      什么意思,请具体讲讲
    to mit263tt:
      你是说连接的pop服务器用pop3.163.com吗,我用foxmail收发邮件都是这么写的。
      

  3.   

    现在的163邮箱已经使用了ajax,并且在操作上也有了改变。你自己应该有163账户吧,自己到邮箱去看看就知道了。
      

  4.   

    它使用不使用ajax跟我这个程序有什么关系?
      

  5.   

    你最好自己登陆163.com去看看,我也不好怎么跟你说了。他现在要你自己设置pop账户,你没设置怎么可以使用呢。
      

  6.   

    楼上,我不明白你的意思,你说设置pop是什么意思?为了什么而要设置,我用foxmail收发是正常的。