title: How to resolve javax.net.ssl.SSLProtocolException: SSL handshake aborted
body: <p>I'm trying to send an email using an account from another server and not <strong>Gmail</strong>, but this exception occurs when sending.</p>
  
  <p>Error:</p>
  
  <pre><code>02-05 16:10:37.688: W/System.err(30346): javax.mail.MessagingException: Could not connect to SMTP host: smtp.suprema.net.br, port: 587;
  02-05 16:10:37.688: W/System.err(30346):   nested exception is:
  02-05 16:10:37.688: W/System.err(30346):    javax.net.ssl.SSLHandshakeException: Handshake failed
  02-05 16:10:37.688: W/System.err(30346):    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
  02-05 16:10:37.688: W/System.err(30346):    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
  02-05 16:10:37.688: W/System.err(30346):    at javax.mail.Service.connect(Service.java:288)
  02-05 16:10:37.688: W/System.err(30346):    at com.prologica.smart_detection.Mail.Send(Mail.java:71)
  02-05 16:10:37.689: W/System.err(30346):    at com.prologica.smart_detection.utils.Utilities.SendMail(Utilities.java:162)
  02-05 16:10:37.689: W/System.err(30346):    at com.prologica.smart_detection.utils.Utilities.NotifyContatcts(Utilities.java:106)
  02-05 16:10:37.689: W/System.err(30346):    at com.prologica.smart_detection.services.NotificationService.NotifyContacts(NotificationService.java:106)
  02-05 16:10:37.689: W/System.err(30346):    at com.prologica.smart_detection.services.NotificationService.GetNotifications(NotificationService.java:79)
  02-05 16:10:37.689: W/System.err(30346):    at com.prologica.smart_detection.services.NotificationService.run(NotificationService.java:61)
  02-05 16:10:37.689: W/System.err(30346):    at java.lang.Thread.run(Thread.java:818)
  02-05 16:10:37.689: W/System.err(30346): Caused by: javax.net.ssl.SSLHandshakeException: Handshake failed
  02-05 16:10:37.689: W/System.err(30346):    at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
  02-05 16:10:37.689: W/System.err(30346):    at com.android.org.conscrypt.OpenSSLSocketImpl.waitForHandshake(OpenSSLSocketImpl.java:598)
  02-05 16:10:37.689: W/System.err(30346):    at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:560)
  02-05 16:10:37.689: W/System.err(30346):    at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:1449)
  02-05 16:10:37.689: W/System.err(30346):    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1366)
  02-05 16:10:37.689: W/System.err(30346):    ... 9 more
  02-05 16:10:37.689: W/System.err(30346): Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb7617058: Failure in SSL library, usually a protocol error
  02-05 16:10:37.689: W/System.err(30346): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:790 0xae73aedd:0x00000000)
  02-05 16:10:37.690: W/System.err(30346):    at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
  02-05 16:10:37.690: W/System.err(30346):    at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
  02-05 16:10:37.690: W/System.err(30346):    ... 13 more
  </code></pre>
  
  <p><strong>My Method</strong></p>
  
  <pre><code> public Boolean Send(String localFile, String subject, String body, String recipients)
   {  
      Boolean ret = false;
  
      try
      {  
          String user = MailSenderConfiguration.USER;
          String pass = MailSenderConfiguration.PASSWORD;
  
          Properties props = System.getProperties();  
          props.setProperty("mail.transport.protocol", "smtp");   
          props.setProperty("mail.host", MailSenderConfiguration.SMTP);   
          props.put("mail.smtp.auth", "true");   
          //props.put("mail.smtp.starttls.enable", "true");
          props.put("mail.smtp.port", MailSenderConfiguration.PORT);   
          props.put("mail.smtp.socketFactory.port", MailSenderConfiguration.PORT);   
          props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");   
          props.put("mail.smtp.socketFactory.fallback", "false");   
          props.setProperty("mail.smtp.quitwait", "false");   
  
          Authenticator auth = new Autenticador(user,pass);  
  
          Session session = Session.getDefaultInstance(props, auth); 
  
          MimeMessage msg = new MimeMessage(session);  
          msg.setFrom(new InternetAddress(user));  
  
           if (recipients.indexOf(',') &gt; 0)   
                  msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
              else  
                  msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
          //msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(recipients));
  
          msg.setSentDate(new Date());  
          msg.setSubject(subject);  
          MimeBodyPart textPart = new MimeBodyPart();  
          textPart.setContent(body, "text/plain");  
          Multipart mp = new MimeMultipart();  
          mp.addBodyPart(textPart);  
          msg.setContent(mp);  
          msg.saveChanges();  
          Transport transport = session.getTransport("smtp");  
          transport.connect(MailSenderConfiguration.SMTP, Integer.parseInt(MailSenderConfiguration.PORT), user, pass);  
          transport.sendMessage(msg, msg.getAllRecipients());  
          transport.close();   
  
          ret = true;
      }
      catch(Exception e)
      {  
          e.printStackTrace();
      }  
  
      return ret;
  } 
  </code></pre>