is starttls.enabled = true is safe for mail sending from java code?

为君一笑 提交于 2019-12-22 05:48:42

问题


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

回答1:


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'.




回答2:


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



来源:https://stackoverflow.com/questions/18333594/is-starttls-enabled-true-is-safe-for-mail-sending-from-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!