Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

email

ssl

smtp

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
like image 867
Baurzhan Avatar asked Aug 20 '13 11:08

Baurzhan


People also ask

What is mail SMTP StartTLS enable?

StartTLS is a protocol command used to inform the email server that the email client wants to upgrade from an insecure connection to a secure one using TLS or SSL. StartTLS is used with SMTP and IMAP, while POP3 uses the slightly different command for encryption, STLS.

How to set SSL to true in Java mail?

To enable SMTP connections over SSL, set the "mail. smtp. ssl. enable" property to "true".

How to send email in Java with SMTP server?

Send Mail in Java using SMTP without authentication We need to set the mail. smtp. host property with the SMTP server host. If the SMTP server is not running on default port (25), then you will also need to set mail.


1 Answers

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

like image 65
am5 Avatar answered Nov 14 '22 22:11

am5