我在几个站点上读到,当使用 JavaMail API 时,将属性设置mail.smtp.ssl.enable
为 true。我有一些代码如下:
props.put("mail.smtp.host", "exchangemail1.example.com");
props.put("mail.from", "myemail@example.com");
props.put("mail.smtp.starttls.enable", "true");
// I tried this by itself and also together with ssl.enable)
props.put("mail.smtp.ssl.enable", "true");
Session session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, "me.at@example.com");
// also tried @gmail.com
msg.setSubject("JavaMail ssl test");
msg.setSentDate(new Date());
msg.setText("Hello, world!\n");
props.put("mail.smtp.auth", "false");
Transport trnsport;
trnsport = session.getTransport("smtp");
trnsport.connect();
msg.saveChanges();
trnsport.sendMessage(msg, msg.getAllRecipients());
trnsport.close();
这会发送电子邮件,但是:
- 当我进行流量捕获时,我看到它没有加密
- 使用调试(
props.put("mail.debug", "true")
)时,我看到“isSSL false”
(我也尝试在上面添加props.put("mail.smtp.auth","true")
+用户/密码....)
任何想法我做错了什么?