我設置mail.transport屬性SMTPS,非常基本的信息旁邊,用於連接到服務器的SMTPS:的JavaMail返回SMTP作爲交通工具,而不是SMTPS
Properties p = new Properties();
p.put("mail.transport.protocol", "smtps");
p.put("mail.smtps.host", "smtp.gmail.com");
p.put("mail.smtps.auth", true);
Session s = Session.getDefaultInstance(p,new Authenticator(){/*authenticator impl.*/});
MimeMessage mm = new MimeMessage(s); /*then i set the subject, then the body... */
mm.setRecipients(RecipientType.TO, "[email protected]");
而現在,我嘗試把我的消息。我想嘗試靜態方法;使用實例方法sendMessage
它工作正常。那就是:
Transport.send(mm);
它會嘗試連接,而不是一個SMTPS服務器到SMTP服務器。 JavaMail的實現內部的步進(順便說一句,我的版本是1.4.5),我發現,失敗的方法是:
transport = s.getTransport(addresses[0]);
,因爲它返回一個SMTPTransport
代替SMTPSSLTransport
;即使我已將mail.transport.protocol
屬性設置爲smtps,如您在第二行代碼中所看到的那樣。 我的手術車是否在任何地方,或者不可能通過Transport.send
靜態方法發送smtps郵件?
http://stackoverflow.com/questions/5515410/javamail-smtps-imaps –