Telnet ile mail sistemine erişim yapabiliyorum. "+OK The Microsoft Exchange POP3 service is ready."
Pop3 protokolü ile mailleri okumak için test amaçlı yazdığım fonksiyon:
public static void test(final String host, final String username, final String password, final int port) throws Exception {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "pop3");
props.setProperty("mail.pop3.host", host);
props.setProperty("mail.pop3.port", String.valueOf(port));
props.setProperty("mail.pop3.username", username);
props.setProperty("mail.pop3.password", password);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.debug", "true");
try {
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
Store store = session.getStore();
store.connect(host, 110, username, password);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message msg = inbox.getMessage(inbox.getMessageCount());
Address[] in = msg.getFrom();
for (Address address : in) {
System.out.println("FROM:" + address.toString());
}
Multipart mp = (Multipart) msg.getContent();
BodyPart bp = mp.getBodyPart(0);
System.out.println("SENT DATE:" + msg.getSentDate());
System.out.println("SUBJECT:" + msg.getSubject());
System.out.println("CONTENT:" + bp.getContent());
} catch (Exception mex) {
mex.printStackTrace();
}
}
Ve aldığım hata ve debug logları:
DEBUG POP3: connecting to host "192.168.xx.xx", port 110, isSSL false
S: +OK The Microsoft Exchange POP3 service is ready.
C: USER xxx\\xxx
S: -ERR Command is not valid in this state.
C: QUIT
S: +OK Microsoft Exchange Server 2010 POP3 server signing off.
javax.mail.AuthenticationFailedException: Command is not valid in this state.
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:128)
at javax.mail.Service.connect(Service.java:258)
at com.cbi.mail.test.Pop3Test.test(Pop3Test.java:51)
at com.cbi.mail.test.Pop3Test.main(Pop3Test.java:31)