title: Unable to Send Mail - javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
body: <p>We are sending Mail using Spring <strong>JavaMailSenderImpl</strong>. Following is the configuration</p>
  
  <pre class="lang-xml prettyprint-override"><code> &lt;bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
          &lt;property name="host" value="${host}"/&gt;
          &lt;property name="port" value="${port}"/&gt;
          &lt;property name="username" value="${mail.username}"/&gt;
          &lt;property name="password" value="${mail.password}"/&gt;
          &lt;property name="javaMailProperties"&gt;
              &lt;props&gt;
                  &lt;!-- Use SMTP transport protocol --&gt;
                  &lt;prop key="mail.transport.protocol" &gt;${mail.transport.protocol}&lt;/prop&gt;
                  &lt;!-- Use SMTP-AUTH to authenticate to SMTP server --&gt;
                  &lt;prop key="mail.smtp.auth"&gt;${mail.smtp.auth}&lt;/prop&gt;
                  &lt;!-- Use TLS to encrypt communication with SMTP server --&gt;
                  &lt;prop key="mail.smtp.starttls.enable"&gt;${mail.smtp.starttls.enable}&lt;/prop&gt;
                  &lt;prop key="mail.debug"&gt;false&lt;/prop&gt;
                  &lt;prop key="mail.smtp.ssl.enable"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Properties File :-</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>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
  </code></pre>
  
  <p><strong>Console Logs</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>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
  </code></pre>
  
  <p>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 ?</p>