Java Socket - POP3 - 检查是否有新邮件

时间:2016-12-03 17:34:28

标签: java sockets pop3

所以如果我有新邮件,我想每3秒检查一次。在我的邮箱上,我现在有9封邮件,所以这是我的程序的结果:

Test
1 0a061c60b94e11e6
Test
2 0ab96602b94e11e6
Test
3 8c644458b96211e6
Test
4 1f057024b96611e6
Test
5 b309f824b96611e6
Test
6 c9018332b96611e6
Test
7 1c614f11b96811e6
Test
8 a7b0a6d7b96a11e6
Test
9 0c669444b97d11e6
Test
.
Test

当我发送新邮件时,我没有收到任何消息。我应该得到:

10 some_letters_and_numbers

但没有任何反应。我甚至不会每3秒看一次“测试”。它停止了。这是我的代码:

public void makeConnection(ConfigData configData) throws IOException {
    socket = new Socket(configData.getServerAddress(), configData.getPort());
    reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    String response = reader.readLine();
    sendCommand("USER " + configData.getUsername());
    sendCommand("PASS " + configData.getPassword());
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.scheduleAtFixedRate(mailRunnable, 0, 3, TimeUnit.SECONDS);
}
protected String sendCommand(String command) throws IOException {
    writer.write(command + "\n");
    writer.flush();
    String response = reader.readLine();
    return response;
}
Runnable mailRunnable = new Runnable() {
    public void run() {
        try {
            System.out.println("Test");
            String response = reader.readLine();
            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
};

有人可能知道我做错了什么?

0 个答案:

没有答案