Search code examples
javaemailsmtpimap

Property "mail.imap.starttls.enable", "true" doesn't work


It is said in Oracl sslnotes, that STARTTLS command should be enabled by using mail.imap.starttls.enable or mail.smtp.starttls.enable, to "true". "When set, if the server supports the STARTTLS command, it will be used after making the connection and before sending any login information". So, I set this as suggested:

props.setProperty("mail.imap.starttls.enable", "true");
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.auth", "true");
props.setProperty("mail.imap.host", "imap.mail.ru");

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(login + "@" + server, passwd);
    }
});

session.setDebug( true);
Store store = session.getStore();

store.connect();

but here's the dialogue:

* OK Welcome
A0 CAPABILITY
* CAPABILITY IMAP4rev1 ID XLIST UIDPLUS UNSELECT MOVE STARTTLS LIST-STATUS LOGINDISABLED
A0 OK CAPABILITY completed
A1 LOGIN [email protected] tester   <==== this string is edited
A1 NO [PRIVACYREQUIRED] Command disabled. Please use STARTTLS first.

As I understand there's no STARTTLS command sending by connect function (though that command should be send "after making connection and before sending any login information", as it promised in Oracle manual). So what should I do to make code send this STARTTLS?


Solution

  • Solved by downloading latest javax.mail.jar. Thanks to all.