title: Unsupported or unrecognized SSL message
body: <p>I am trying to send emails from outlook email in Java+ springboot.</p>
  <p>below are the configuration:</p>
  <pre><code>@Service
  public class EmailService {
  
      
      String  from_address = &quot;no-reply@jpmorganchase.com&quot;,
              password = &quot;somepassword!sd#&quot;,
              host = &quot;smtp.office365.com&quot;,
              port = &quot;587&quot;,
              to_address = &quot;no-reply@jpmorganchase.com&quot;,
              mail_subject = &quot;Test&quot;,
              mail_content = &quot;testing mail&quot;,
               username=&quot;&quot;,
              user_password=&quot;&quot;;
      
      
       public void sendmail(UserBean user,String uname, String pword)
          {
              username=uname;
              user_password=pword;
              to_address= user.getEmail();
              Properties props = new Properties();
              props.put(&quot;mail.smtp.user&quot;, from_address);
              props.put(&quot;mail.smtp.host&quot;, host);
              props.put(&quot;mail.smtp.port&quot;, port);
              props.put(&quot;mail.smtp.starttls.enable&quot;,&quot;true&quot;);
              props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);
              props.put(&quot;mail.smtp.debug&quot;, &quot;true&quot;);
              props.put(&quot;mail.smtp.socketFactory.port&quot;, port);
              props.put(&quot;mail.smtp.socketFactory.class&quot;, &quot;javax.net.ssl.SSLSocketFactory&quot;);
              props.put(&quot;mail.smtp.socketFactory.fallback&quot;, &quot;false&quot;);
              mail_content = 
                       &quot;Hello &quot;+user.getName()+&quot;\n&quot;
                              +&quot;Experience &quot;+user.getExperience()+&quot;\n&quot;
                              + &quot;Email &quot;+user.getEmail()+&quot;\n&quot;
                              + &quot;Set allocated: &quot;+user.getSet()+&quot;\n&quot;
                              +&quot;Mobile number &quot;+user.getPhone()+&quot;\n&quot;+&quot;\n&quot;
                              + &quot;Your login credentials are: &quot;+&quot;\n&quot;
                              +&quot;User Name: &quot;+username+&quot;\n&quot;
                              +&quot;Password:  &quot; + user_password+&quot;\n&quot;+&quot;\n&quot;
                              + &quot;Click on link to take test   &quot;+&quot;https://www.jpmorganchase.com/en_sg&quot;+&quot;\n&quot; 
                              +  &quot;Message from jpmorganchase&quot;+user.getMessage()+&quot;\n&quot;;
                      
              mail_subject = &quot;jpmorganchase Online Assesment Test&quot;;
              SecurityManager security = System.getSecurityManager();
  
              try
              {
                  Authenticator auth = new SMTPAuthenticator();
                  Session session = Session.getInstance(props, auth);
                  session.setDebug(true);
                  MimeMessage msg = new MimeMessage(session);
                  msg.setText(mail_content);
                  msg.setSubject(mail_subject);
                  msg.setFrom(new InternetAddress(from_address));
                  msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to_address));
                  Transport.send(msg);
              }
              catch (Exception mex)
              {
                  mex.printStackTrace();
              } 
          }
       
       public void sendConfirmationMail(User user, String confirmationToken)
          {
              Properties props = new Properties();
              props.put(&quot;mail.smtp.user&quot;, from_address);
              props.put(&quot;mail.smtp.host&quot;, host);
              props.put(&quot;mail.smtp.port&quot;, port);
              props.put(&quot;mail.smtp.starttls.enable&quot;,&quot;true&quot;);
              props.put(&quot;mail.smtp.ssl.enable&quot;,&quot;true&quot;);
              props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);
              props.put(&quot;mail.smtp.debug&quot;, &quot;true&quot;);
              props.put(&quot;mail.smtp.socketFactory.port&quot;, port);
              props.put(&quot;mail.smtp.socketFactory.class&quot;, &quot;javax.net.ssl.SSLSocketFactory&quot;);
              props.put(&quot;mail.smtp.socketFactory.fallback&quot;, &quot;false&quot;);
              mail_content = 
                       &quot;Hello &quot;+user.getName()+&quot;\n&quot;
                       +&quot;To confirm your account, please click here : &quot;
                          +&quot;http://localhost:8080/jpmorganchase/confirm-account?token=&quot;+confirmationToken;
              mail_subject=&quot;Complete Registration!&quot;;
             // String mail[] = user.getEmail().split(&quot;@&quot;);
              //to_address = mail[0]+&quot;@gmail.com&quot;;
              to_address = user.getEmail();
                              
              SecurityManager security = System.getSecurityManager();
  
              try
              {
                  Authenticator auth = new SMTPAuthenticator();
                  Session session = Session.getInstance(props, auth);
                  session.setDebug(true);
                  MimeMessage msg = new MimeMessage(session);
                  msg.setText(mail_content);
                  msg.setSubject(mail_subject);
                  msg.setFrom(new InternetAddress(from_address));
                  msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to_address));
                  Transport.send(msg);
              }
              catch (Exception mex)
              {
                  mex.printStackTrace();
              } 
          }
  
  }
  </code></pre>
  <p><strong>I am getting the below exception:</strong></p>
  <blockquote>
  <pre><code>DEBUG: setDebug: JavaMail version 1.5.6
  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: need username and password for authentication
  DEBUG SMTP: protocolConnect returning false, host=smtp.office365.com, user=no-reply@jpmorganchase.com,
  password=&lt;null&gt;
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host &quot;smtp.office365.com&quot;, port 587, isSSL false
  javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
    nested exception is:
    javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2120)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712)
  </code></pre>
  </blockquote>
  <p>Have tried various solutions over internet but no luck.</p>