is starttls.enabled = true is safe for mail sendin

2019-04-28 08:59发布

I'm sending emails from java code.My configuration is

 props.put("mail.smtp.starttls.enable", "true");
 props.put("mail.smtp.host", "****"); 
 props.put("mail.smtp.auth", "true");
 props.put("mail.smtp.port", "587");

On my other question EJP answered

Any protocol that uses STARTTLS is in SSL mode after the STARTTLS command is issued

But my debug output shows:DEBUG SMTP: trying to connect to host "****", port 587, isSSL false.

So my question sounds like

Is such configuration really safe and uses SSL as EJP said despite of isSSL=false on my debug output?

UPDATE

connecting code

 Transport transport = session.getTransport("smtp");
 transport.connect("host", 587,"username", "password");

when I wrote Transport transport = session.getTransport("smtps") I got

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection

2条回答
爷、活的狠高调
2楼-- · 2019-04-28 09:29

Set mail.smtp.starttls.required=true This ensures TLS is used or connection won't happen REF: https://javamail.java.net/nonav/docs/api/com/sun/mail/smtp/package-summary.html

查看更多
混吃等死
3楼-- · 2019-04-28 09:35

You should still use the 'smtp' transport as that is the protocol (smtps is not an known protocol). SSL is used for the connection. I myself have used 'javax.mail' in conjunction with Google. Google only allows SSL. So I can only answer yes; it works and it is safe. I should add that the property 'mail.smtp.starttls.enable' is a bit confusing. The startsll property refers to the command that is being issued but it should have been named: 'mail.smtp.secure.enable'.

查看更多
登录 后发表回答