Java imap连接到有和没有ssl的商店

时间:2016-03-30 01:48:52

标签: java ssl javamail imap

我正在尝试连接到基于用户服务器的imap商店。例如,我有多个服务器,如143与ssl,和993没有ssl。当我尝试连接到143 ssl服务器时,它说明了连接。有没有办法连接到这样的商店?

除了java中的javamail之外还有其他IMAP吗?

以下一些代码 - >

Properties props = System.getProperties();
String imapProtocol = server.getImapSsl() != null && server.getImapSsl() == true ? "imaps" : "imap";
props.put("mail.store.protocol", imapProtocol);
props.put("mail." + imapProtocol + ".port", server.getImapPort());
props.put("mail." + imapProtocol + ".host", server.getImapHost());

javax.mail.Session mailSession = javax.mail.Session.getInstance(props, null);
Store store = mailSession.getStore();
store.connect(server.getImapHost(), server.getImapPort(), username, password);

更新(调试) - >

DEBUG IMAP: enable STARTTLS
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: trying to connect to host "imap.itheme.mn", port 143, isSSL false
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE NAMESPACE STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: LOGIN
DEBUG IMAP: protocolConnect login, host=imap.somemail.mn, user=zolboo@itheme.mn, password=<non-null>
A0 STARTTLS
A0 OK Begin TLS negotiation now.
A1 CAPABILITY
* CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE NAMESPACE AUTH=PLAIN AUTH=LOGIN
A1 OK Pre-login capabilities listed, post-login capabilities have more.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: LOGIN
DEBUG IMAP: AUTHENTICATE LOGIN command trace suppressed
DEBUG IMAP: AUTHENTICATE LOGIN command result: A2 NO [AUTHENTICATIONFAILED] Authentication failed.

1 个答案:

答案 0 :(得分:1)

您的端口号码倒退了。 143是纯文本。