【问题标题】:javamail AuthenticationFailedException: EOF on socketjavamail AuthenticationFailedException:套接字上的 EOF
【发布时间】:2019-05-12 10:49:19
【问题描述】:

我编写了一个程序来使用 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 上运行。在 Raspberry 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 上修复它?

【问题讨论】:

  • 请将Store store = session.getStore("pop3"); 更改为Store store = session.getStore("pop3s");,让我知道它是否有效
  • 不行:javax.mail.AuthenticationFailedException: failed to connect at javax.mail.Service.connect(Service.java:403) 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)
  • 您是否也将所有属性都更改为pop3s?我的意思是mail.pop3.* 应该改为mail.pop3s.*
  • 有效吗??
  • 是的,所有属性中的 pop3s 都有效。谢谢! ssl 握手有新问题,但我通过properties.setProperty("mail.pop3s.ssl.trust", "*"); 解决了它

标签: java jakarta-mail raspberry-pi3 pop3


【解决方案1】:

您可以通过将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" );

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      • 2014-06-15
      • 2018-10-17
      • 1970-01-01
      • 2020-02-04
      • 2012-01-14
      相关资源
      最近更新 更多