Results 1 to 3 of 3
  1. #1
    uhrincs is offline Member
    Join Date
    Mar 2017
    Posts
    1
    Rep Power
    0

    Default gmail connection problem only in linux

    Hi I have a problem with gmail. I would like to send email with javamail. Everything is OK on my windows computer, but unfortunately in my raspberry pi I get error message every time. I can not find the solution since weeks. I tryed everything with the certificates but did not work.

    code :

    class SendMailSSL{

    String OwnEmail;
    String OwnPassword;
    String SendTo;
    String TempString = " ";

    private Session session = null;
    private Store store = null;
    public SendMailSSL(String corners) throws Exception{




    // try {
    System.out.println("-- Alarm Thread Email--");




    OwnEmail = "xxxx@gmail.com";
    OwnPassword = "xxxx";
    SendTo = "yyyy@gmail.com";

    System.out.println("___1");



    {
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
    "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.ssl.enable", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.ssl.trust", "*");
    props.put("mail.smtp.password", OwnPassword);
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.auth.debug", "true");
    props.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(props,
    new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(OwnEmail,OwnPassword);
    }
    });

    try {

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(OwnEmail));
    message.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse("yyyyy@gmail.com"));
    message.setSubject("Testing Subject");
    message.setText("Dear Mail Crawler," +
    "\n\n No spam to my email, please!");

    Transport.send(message);

    System.out.println("Done");

    } catch (MessagingException e) {
    throw new RuntimeException(e);
    }
    }


    }
    }

    error message :



    javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
    nested exception is:
    javax.net.ssl.SSLException: java.lang.IllegalStateException
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1972)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SM TPTransport.java:642)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at SendMailSSL.<init>(SendMailSSL.java:98)
    at EmailSender.run(EmailSender.java:81)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.net.ssl.SSLException: java.lang.IllegalStateException
    at sun.security.ssl.Alerts.getSSLException(Alerts.jav a:208)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl .java:1949)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl .java:1906)
    at sun.security.ssl.SSLSocketImpl.handleException(SSL SocketImpl.java:1889)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLS ocketImpl.java:1410)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLS ocketImpl.java:1387)
    at com.sun.mail.util.SocketFetcher.configureSSLSocket (SocketFetcher.java:548)
    at com.sun.mail.util.SocketFetcher.createSocket(Socke tFetcher.java:352)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFe tcher.java:233)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1938)
    ... 9 more
    Caused by: java.lang.IllegalStateException
    at sun.security.ec.ECDHKeyAgreement.deriveKey(Native Method)
    at sun.security.ec.ECDHKeyAgreement.engineGenerateSec ret(ECDHKeyAgreement.java:130)
    at sun.security.ec.ECDHKeyAgreement.engineGenerateSec ret(ECDHKeyAgreement.java:163)
    at javax.crypto.KeyAgreement.generateSecret(KeyAgreem ent.java:648)
    at sun.security.ssl.ECDHCrypt.getAgreedSecret(ECDHCry pt.java:102)
    at sun.security.ssl.ClientHandshaker.serverHelloDone( ClientHandshaker.java:1061)
    at sun.security.ssl.ClientHandshaker.processMessage(C lientHandshaker.java:348)
    at sun.security.ssl.Handshaker.processLoop(Handshaker .java:1026)
    at sun.security.ssl.Handshaker.process_record(Handsha ker.java:961)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocke tImpl.java:1062)
    at sun.security.ssl.SSLSocketImpl.performInitialHands hake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLS ocketImpl.java:1403)
    ... 14 more
    java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
    nested exception is:
    javax.net.ssl.SSLException: java.lang.IllegalStateException
    ^C





    With telnet I can connect to smpt.gmail.com 465.


    Please help!

  2. #2
    gozzy is offline Member
    Join Date
    Jan 2017
    Posts
    46
    Rep Power
    0

    Default Re: gmail connection problem only in linux

    Java Code:
    -Djavax.net.debug=ssl
    as a JVM parameter might throw some light. I suspect you might have an old SSL stack on your Pi which is causing the handshake to fail. Always update the OS

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,342
    Rep Power
    12

    Default Re: gmail connection problem only in linux

    Yeah, the "javax.net.ssl.SSLException:" is key here - also be aware that OpenJDK and Oracle JDK are a little different with their SSL settings - the former sometimes barfing on SSL config the latter is ok with.

    As gozzy mentioned, see if you can update your java version, or switch to the oracle JDK. We've run into this same problem before with OpenJDK - it could be you need to add to or modify the certificate trust store. If Oracle JDK/JVM is an option, try that first.

Similar Threads

  1. Replies: 4
    Last Post: 08-14-2014, 02:02 PM
  2. Creating database connection in linux
    By mangesh.gho in forum JDBC
    Replies: 4
    Last Post: 01-04-2012, 05:35 PM
  3. Java Sqlite Connection in Linux
    By sridaran in forum JDBC
    Replies: 1
    Last Post: 02-07-2011, 07:20 PM
  4. Replies: 0
    Last Post: 10-16-2010, 10:03 AM
  5. Replies: 0
    Last Post: 07-29-2010, 01:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •