【问题标题】:Connecting to mail server连接邮件服务器
【发布时间】:2012-08-23 16:16:14
【问题描述】:

我有以下异常:

  javax.mail.MessagingException: Connect failed;
      nested exception is: 
        java.io.IOException: Connect failed
        at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)
        at javax.mail.Service.connect(Service.java:234)
        at javax.mail.Service.connect(Service.java:135)
        at SimpleReceiver.receive(SimpleReceiver.java:50)
        at SimpleReceiver.main(SimpleReceiver.java:29)

我该如何解决这个问题? 这是代码:

Store store = null;
        Folder folder = null;
        try {
            //Get hold of the default session
            Properties props = System.getProperties();
            props.put("mail.store.protocol", "pop3");
            props.put("mail.pop3.port", "25");
            props.put("mail.pop3.host", "admin");
            props.put("mail.pop3.auth", "true");
            //Session session = Session.getDefaultInstance(props, null);
            Session session = Session.getInstance(props);
            //Get hold of a POP3 message store, and connect to it
            store = session.getStore("pop3");
            store.connect("pop3", 25, "admin", "1234");
            //Try to get hold of the default folder --
            folder = store.getDefaultFolder();
            if (folder == null)
                throw new Exception("No default folder");
            // and its INBOX --
            folder = folder.getFolder("INBOX");
            if (folder == null)
                throw new Exception("No POP3 INBOX");
            //Open the folder for read only --
            folder.open(Folder.READ_ONLY);
            // Get the message wrappers and process them --
            Message[] msgs = folder.getMessages();
            for (int msgNum = 0; msgNum < msgs.length; msgNum++) {
                printMessage(msgs[msgNum]);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            //Close down nicely --
            try {
                if (folder != null)
                    folder.close(false);
                if (store != null)
                    store.close();
            } catch (Exception ex2) {
                ex2.printStackTrace();
            }
        }
    }

那么为什么会出现以下异常:

  javax.mail.MessagingException: Connect failed;
      nested exception is: 
        java.io.IOException: Connect failed

.................................................. .........................................

【问题讨论】:

    标签: java


    【解决方案1】:
    store.connect("pop3","admin","Your_Required_Password");
    

    您还可以查看以下链接:1 & 2

    【讨论】:

      猜你喜欢
      • 2013-07-02
      • 2015-11-22
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 2018-11-11
      相关资源
      最近更新 更多