We are sending Mail using Spring JavaMailSenderImpl. Following is the configuration
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${host}"/>
<property name="port" value="${port}"/>
<property name="username" value="${mail.username}"/>
<property name="password" value="${mail.password}"/>
<property name="javaMailProperties">
<props>
<!-- Use SMTP transport protocol -->
<prop key="mail.transport.protocol" >${mail.transport.protocol}</prop>
<!-- Use SMTP-AUTH to authenticate to SMTP server -->
<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
<!-- Use TLS to encrypt communication with SMTP server -->
<prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
<prop key="mail.debug">false</prop>
<prop key="mail.smtp.ssl.enable">true</prop>
</props>
</property>
</bean>
Properties File :-
host=XXXX.XXXX.XX
port=25
mail.username=xxxxxxxx
mail.password=xxxxxxx
mail.transport.protocol=smtp
mail.smtp.auth=true
mail.smtp.starttls.enable=true
Console Logs
Exception in thread "taskExecutor-2" org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: XXXX.XXXX.XX, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: XXXX.XXXX.XX, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: Could not connect to SMTP host: XXXX.XXXX.XX, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:336)
at com.XXXX.Mailer$1.run(Mailer.java:52)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:671)
at sun.security.ssl.InputRecord.read(InputRecord.java:504)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
... 9 more
We are convinced that this is not related to the SSL certificate as there are other web applications deployed in the same server which sends email perfectly with the same configuration. What could be the issue here ?
The unrecognized ssl message plaintext connection error happens due to an established connection with the client machine that is not secure. You can use numerous methods to debug this error from your syntax, and this article features it all.
javax.net.ssl.SSLException. Known direct subclasses. SSLHandshakeException, SSLKeyException, SSLPeerUnverifiedException, SSLProtocolException. SSLHandshakeException. Indicates that the client and server could not negotiate the desired level of security.
SMTP is an acronym for Simple Mail Transfer Protocol. It is an Internet standard for electronic mail (e-mail) transmission across Internet Protocol (IP) networks. SMTP uses TCP port 25. SMTP connections secured by SSL are known by the shorthand SMTPS, though SMTPS is not a protocol in its own right.
<prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
<prop key="mail.smtp.ssl.enable">true</prop>
You want either mail.smtp.ssl.enable
for implicit SSL directly after TCP connect (port 465) or mail.smtp.starttls.enable
for explicit SSL using the STARTTLS command (port 25). But with your current properties you set both to true.
This means it will do a TCP connect to port 25 and try a SSL handshake there. This will fail because the server is sending a plain text greeting from the SMTP dialog and not the expected SSL handshake. Thus you get
Unrecognized SSL message, plaintext connection?
To fix it make sure that you either use implicit or explicit SSL but not both depending on the port, i.e. for port 25 mail.smtp.ssl.enable
should be false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With