I read on several sites that, when using the JavaMail API, to set the property mail.smtp.ssl.enable
to true. I have some code as follows:
props.put("mail.smtp.host", "exchangemail1.example.com");
props.put("mail.from", "[email protected]");
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, "[email protected]");
// 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();
This sends email, but:
- when I do traffic capture, I see it is not encrypted
- When using debug (
props.put("mail.debug", "true")
), I see that "isSSL false"
(I also tried above adding in props.put("mail.smtp.auth","true")
+ user/password....)
Any ideas what I am doing wrong?