微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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");

原文地址:https://www.jb51.cc/java/123777.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐