我試圖連接到郵箱本地託管的電子郵件POP3郵箱和顯示電子郵件,但我不斷收到錯誤:連接到本地POP3郵箱的Java
Exception in thread "main" javax.mail.MessagingException: Connect failed; nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:209)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at com.kami.utils.MailClient.checkInbox(MailClient.java:33)
at com.kami.Main.main(Main.java:38)
我的類看起來是這樣的:
public class MailClient {
private String host;
private String username;
private String password;
private String provider;
protected Session session;
public MailClient() {
Properties props = new Properties();
this.host = "localhost";
this.username = "unix-user";
this.password = "unix-password";
this.provider = "pop3";
this.session = Session.getDefaultInstance(props, null);
}
public void checkInbox() throws MessagingException, IOException {
Store store = session.getStore(provider);
store.connect(host, username, password); //This is line 33
Folder inbox = store.getFolder("inbox");
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages();
for(Message message : messages){
System.out.println(message.getReceivedDate());
System.out.println(message.getSubject());
}
inbox.close(true);
store.close();
}
}
據本地託管使用達夫科特IMAP/POP3服務器版本2.2.9和Postfix郵件服務器Postfix的版本2.11.0
AFAIK java pop3實現用於連接的郵箱。您是否嘗試連接已下載的pop3郵箱? – Xvolks
連接到一個本地託管的,就像我可以像這樣發送電子郵件:'props.put(「mail.smtp.host」,「localhost」);' – Shepard
本地託管是讓我感到困惑的。你有一臺郵件服務器在你的linux系統上運行(pop3/pop3s服務正在運行)嗎? – Xvolks