title: How to fix javax.net.ssl.SSLHandshakeException even though i have already added the certificate
body: <p>I am working on a script to control my lights and because I'm lazy the communication is via email (works decently fast I know because it used to run on python but I'm writing it in java for some separate reasons) know the issue is I keep getting a <code>javax.net.ssl.SSLHandshakeException</code> error and I tried this <a href="https://stackoverflow.com/questions/6659360/how-to-solve-javax-net-ssl-sslhandshakeexception-error">overflow page</a> but even though I added the trusted certificate it doesn't work and I keep getting the same error the following is my code, the full error, and a picture showing I have the certificate added</p>
  <pre><code>import java.util.Properties;
  
  import javax.mail.Folder;
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.NoSuchProviderException;
  import javax.mail.Session;
  import javax.mail.Store;
  
  public class test {
  
      public static void check(String host, String storeType, String user,
                               String password)
      {
          try {
  
              //create properties field
              Properties properties = new Properties();
  
              properties.put(&quot;mail.pop3.host&quot;, host);
              properties.put(&quot;mail.pop3.port&quot;, &quot;995&quot;);
              properties.put(&quot;mail.pop3.starttls.enable&quot;, &quot;true&quot;);
              Session emailSession = Session.getDefaultInstance(properties);
  
              //create the POP3 store object and connect with the pop server
              Store store = emailSession.getStore(&quot;pop3s&quot;);
  
              store.connect(host, user, password);
  
              //create the folder object and open it
              Folder emailFolder = store.getFolder(&quot;INBOX&quot;);
              emailFolder.open(Folder.READ_ONLY);
  
              // retrieve the messages from the folder in an array and print it
              Message[] messages = emailFolder.getMessages();
              System.out.println(&quot;messages.length---&quot; + messages.length);
  
              for (int i = 0, n = messages.length; i &lt; n; i++) {
                  Message message = messages[i];
                  System.out.println(&quot;---------------------------------&quot;);
                  System.out.println(&quot;Email Number &quot; + (i + 1));
                  System.out.println(&quot;Subject: &quot; + message.getSubject());
                  System.out.println(&quot;From: &quot; + message.getFrom()[0]);
                  System.out.println(&quot;Text: &quot; + message.getContent().toString());
  
              }
  
              //close the store and folder objects
              emailFolder.close(false);
              store.close();
  
          } catch (NoSuchProviderException e) {
              e.printStackTrace();
          } catch (MessagingException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args) {
  
          String host = &quot;pop.gmail.com&quot;;// change accordingly
          String mailStoreType = &quot;pop3&quot;;
          String username = &quot;EMAIL&quot;;// change accordingly
          String password = &quot;PASSWORD&quot;;// change accordingly
  
          check(host, mailStoreType, username, password);
      
          }
  
  }
  </code></pre>
  <p>Error</p>
  <pre><code>javax.mail.MessagingException: Connect failed;
    nested exception is:
      javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
      at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:160)
      at javax.mail.Service.connect(Service.java:291)
      at javax.mail.Service.connect(Service.java:172)
      at test.check(test.java:28)
      at test.main(test.java:68)
  Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
      at java.base/sun.security.ssl.HandshakeContext.&lt;init&gt;(HandshakeContext.java:172)
      at java.base/sun.security.ssl.ClientHandshakeContext.&lt;init&gt;(ClientHandshakeContext.java:98)
      at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
      at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:434)
      at java.base/sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketImpl.java:904)
      at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:995)
      at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:244)
      at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:263)
      at java.base/java.io.DataInputStream.readLine(DataInputStream.java:519)
      at com.sun.mail.pop3.Protocol.simpleCommand(Protocol.java:359)
      at com.sun.mail.pop3.Protocol.&lt;init&gt;(Protocol.java:101)
      at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:213)
      at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:156)
      ... 4 more
  
  Process finished with exit code 0
  </code></pre>
  <p><a href="https://i.stack.imgur.com/7iWtW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7iWtW.png" alt="Proof i have the certificate added" /></a></p>
  <p>Java.Security</p>
  <p><a href="https://i.stack.imgur.com/fipbw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fipbw.png" alt="java Security" /></a></p>
  <p>This is the error when you delete TLS1 and leave TSL 1.1</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: javax/activation/DataSource
      at com.sun.mail.pop3.POP3Folder.createMessage(POP3Folder.java:326)
      at com.sun.mail.pop3.POP3Folder.getMessage(POP3Folder.java:307)
      at javax.mail.Folder.getMessages(Folder.java:943)
      at test.check(test.java:35)
      at test.main(test.java:68)
  Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
      ... 5 more
  </code></pre>