我在几个网站上阅读,当使用
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”)用户/密码….)
任何想法我做错了什么?