JavaMail mail. smtp. ssl. Enable does not work

I read on several websites that when using the JavaMail API, the attribute mail smtp. ssl. Enable is set to true I have some codes as follows:

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

This will send an email, but:

>When I do traffic capture, I see that it is not encrypted > when I use debug (props. Put ("mail. Debug", "true"), I see "isssl false"

(I also tried to add props. Put ("mail. SMTP. Auth", "true") user / password...)

Any idea what I did wrong?

Solution

To use SSL, you should change the protocol from SMTP to smtps by changing

trnsport = session.getTransport("smtp");

to

trnsport = session.getTransport("smtps");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>