android javamail api不使用指定端口(STARTTLS)

时间:2014-09-13 15:18:43

标签: android

我尝试通过smtp和STARTTLS加密发送电子邮件。 我的代码:

Properties emailProperties = new Properties();  
emailProperties.setProperty("mail.smtp.host", emailHost); 
emailProperties.put("mail.smtp.auth", "true");   
emailProperties.setProperty("mail.smtp.starttls.enable", "true");
emailProperties.put("mail.smtp.port", emailPort);  
Log.i("GMail", "Mail server properties set.");
mailSession = Session.getInstance(emailProperties, this);
mailSession.setDebug(true);

当我调用Transport.send(...)时,我得到以下日志条目:

09-13 11:10:23.293: I/System.out(2483): DEBUG SMTP: useEhlo true, useAuth false
09-13 11:10:23.293: I/System.out(2483): DEBUG SMTP: trying to connect to host "smtp.web.de", port 465, isSSL true
09-13 11:10:30.323: E/GMail(2483): Could not connect to SMTP host: smtp.web.de, port: 465
09-13 11:10:30.323: E/GMail(2483): javax.mail.MessagingException: Could not connect to SMTP host: smtp.web.de, port: 465;
09-13 11:10:30.323: E/GMail(2483):   nested exception is:
09-13 11:10:30.323: E/GMail(2483):  java.net.ConnectException: failed to connect to smtp.web.de/213.

我的web.de服务器需要端口587.但javamail忽略设置并尝试在端口465连接。当我使用mail.transport.protocol="smtps"时,它使用端口587,但后来我得到一个protocolException。

0 个答案:

没有答案