Java/JavaMail:尝试创建文件夹以获取电子邮件时出现空指针异常 (GMAIL/POP3)


一切

正常,包括身份验证,但是当我进入创建文件夹的步骤时,程序崩溃了。

我试过切换到SMTP,没有用,甚至不确定SMTP是什么,我尝试了其他Gmail帐户,我尝试删除行properties.put("mail.pop3.starttls.enable", "true"),并且我试过从pop3pop3s中删除 3.

    private static void createProperties() {
        // Create properties field.
        Properties properties = new Properties();
        properties.put("mail.pop3.host", host);
        properties.put("mail.store.protocol", "pop3s");
        properties.put("mail.pop3.port", "995");
        //properties.put("mail.pop3.starttls.enable", "true");
        emailSession = Session.getDefaultInstance(properties, null);
    }
    private static void createStore() throws MessagingException {
        // Create the POP3 store object and connect with the POP server.
        Store store = emailSession.getStore("pop3s");
        store.connect(host, user, password);
    }
    private static void createFolder() throws MessagingException {
        // Create the folder object and open it.
        Folder emailFolder = store.getFolder("INBOX"); // Error here
        emailFolder.open(Folder.READ_ONLY);
    }

我希望收到一些格式良好的电子邮件。我收到以下错误:

DEBUG POP3: server doesn't support TOP, disabling it 
Exception in thread "main" java.lang.NullPointerException
    at GetMail.createFolder(GetMail.java:60)
    at GetMail.main(GetMail.java:33)```

POP3 协议仅支持一个文件夹 - 收件箱。 请改用 IMAP。

最新更新