My send email was working last year but I'm wondering why it now gives me a CertPathValidatorException
Update: I tried to use Mkyong's tutorial (TLS) + Overriding socketfactory. However it gives me a different exception.
The stack:
02-09 21:35:29.356    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ javax.mail.MessagingException: Could not convert socket to TLS;
02-09 21:35:29.356    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ nested exception is:
02-09 21:35:29.356    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ java.io.IOException: Exception in startTLS: host smtp.gmail.com, port 587; Exception: java.lang.NoSuchMethodException: getDefault []
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1339)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:420)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at javax.mail.Service.connect(Service.java:310)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at javax.mail.Service.connect(Service.java:169)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at javax.mail.Service.connect(Service.java:118)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at javax.mail.Transport.send0(Transport.java:188)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at javax.mail.Transport.send(Transport.java:118)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sblive.connector.AsyncTasks.SendEmailAsyncTask.sendEmail(SendEmailAsyncTask.java:151)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sblive.connector.AsyncTasks.SendEmailAsyncTask.doInBackground(SendEmailAsyncTask.java:80)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sblive.connector.AsyncTasks.SendEmailAsyncTask.doInBackground(SendEmailAsyncTask.java:29)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
02-09 21:35:29.360    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ Caused by: java.io.IOException: Exception in startTLS: host smtp.gmail.com, port 587; Exception: java.lang.NoSuchMethodException: getDefault []
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:309)
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1334)
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ ... 15 more
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ Caused by: java.lang.NoSuchMethodException: getDefault []
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at java.lang.Class.getConstructorOrMethod(Class.java:423)
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at java.lang.Class.getMethod(Class.java:787)
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sun.mail.util.SocketFetcher.getSocketFactory(SocketFetcher.java:260)
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:292)
02-09 21:35:29.364    1861-1901/com.sblive.aufschoolbliz W/System.err﹕ ... 16 more
Here is my new sendEmail():
 private boolean sendEmail(String from, String to, String subject, String body){
        final String username = activity.getResources().getString(R.string.feedback_sender_email);
        final String password = activity.getResources().getString(R.string.feedback_sender_password);
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.socketFactory.class",
                "com.sblive.connector.MySSLSocketFactory");
        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });
        try {
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(to));
            message.setSubject(subject);
            message.setText(body);
            Transport.send(message);
            return true;
        } catch (MessagingException e) {
            e.printStackTrace();
            return false;
        }
 
     
    