javamail AuthenticationFailedException:套接字上的EOF

时间:2018-12-11 12:29:02

标签: java javamail raspberry-pi3 pop3

我编写了一个程序来检查JavaMail的邮件。这是代码:

private static Folder getFolder(String popHost, int openPort, MailAuthenticator auth) throws MessagingException{
    try{
        store.close();
    }catch(Exception e){
        System.out.println("Store konnte nicht geschlossen werden: "+e.getMessage());
    }
    Properties properties = System.getProperties();
    properties.setProperty("mail.store.protocol", "pop3");
    properties.setProperty("mail.pop3.host", popHost);
    properties.setProperty("mail.pop3.port", String.valueOf(openPort));
    properties.setProperty("mail.pop3.auth", "true");
    properties.setProperty( "mail.pop3.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory" ); 
    Session session = Session.getInstance(properties, auth);
    session.setDebug(true);
    store = session.getStore( "pop3" );
    store.connect();
    return store.getFolder( "INBOX" );

它可以在我的PC上完美运行,但是应该可以在我的Raspberry Pi上运行。在树莓派上, store.connect()抛出AuthenticationFailedException:

DEBUG: setDebug: JavaMail version 1.5.5
DEBUG: getProvider() returning   javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "pop.goneo.de", port 995, isSSL false
<EOF>
javax.mail.AuthenticationFailedException: EOF on socket
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:209)
    at javax.mail.Service.connect(Service.java:388)
    at javax.mail.Service.connect(Service.java:246)
    at javax.mail.Service.connect(Service.java:195)
    at MailInterface.getFolder(MailInterface.java:294)
    at MailInterface.getFolder(MailInterface.java:253)
    at MailWatch.checkMailAccount(MailWatch.java:75)
    at MailWatch.checkMails(MailWatch.java:46)
    at MailWatch.run(MailWatch.java:25)

为什么我的Raspberry无法连接到主机,但是我的PC可以连接?如何在Raspberry上修复它?

2 个答案:

答案 0 :(得分:2)

您可以通过将pop3转换为pop3s来解决此问题:

properties.setProperty("mail.store.protocol", "pop3s");
properties.setProperty("mail.pop3s.host", popHost);
properties.setProperty("mail.pop3s.port", String.valueOf(openPort));
properties.setProperty("mail.pop3s.auth", "true");
properties.setProperty("mail.pop3s.socketFactory.class",
        "javax.net.ssl.SSLSocketFactory" ); 
properties.setProperty("mail.pop3s.ssl.trust", "*");

store = session.getStore( "pop3s" );

答案 1 :(得分:0)

Get rid of all the socket factory settings并将mail.pop3.ssl.enable设置为true。