繁体   English   中英

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

[英]Java/JavaMail: Null pointer exception when trying to create a folder to fetch E-Mails (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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM