JavaMail mail.smtp.ssl.enable不工作

我在几个网站上阅读,当使用 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();

这会发送电子邮件,但是:

>当我做流量捕获,我看到它没有加密
>当使用debug(props.put(“mail.debug”,“true”))时,我看到“isSSL false”

(我也试过上面添加了props.put(“mail.smtp.auth”,“true”)用户/密码….)

任何想法我做错了什么?

解决方法

要使用SSL,您应该通过更改将协议从 SMTP更改为 SMTPS
trnsport = session.getTransport("smtp");

trnsport = session.getTransport("smtps");

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...