Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:54:22+00:00 2026-05-20T10:54:22+00:00

I want to read my emails from ms exchange, I am using java mail

  • 0

I want to read my emails from ms exchange, I am using java mail api from here http://code.google.com/p/javamail-android/ and I have successfully extract the emails from my google account… The problem with exchange is that I have it locally and I don’t have public certificate and android gives me 03-07 13:12:25.708: WARN/System.err(3886): javax.mail.MessagingException: Not trusted server certificate;

How can I pass the certificate check?

I have seen the example of Vynayak from here: Sending Email in Android using JavaMail API without using the default/built-in app

that he uses some TrustManager class and I had tried to make that too but I don’t know how to link the trustFactory class to the imap properties.

So far I have this in my activity:

Properties props = new Properties();
    props.setProperty("mail.store.protocol", "imaps");

    props.setProperty("mail.store.socketFactory.class",
                "com.imap.DummySSLSocketFactory");


    // Prevents to fall into NOT-secure connection
    props.setProperty("mail.pop3.socketFactory.fallback", "false");

    try {
        Session session = Session.getDefaultInstance(props, null);
        Store store = session.getStore("imaps");
        store.connect("mail.domain.com", "user", "pass");

        System.out.println(store);

        Folder inbox = store.getFolder("Inbox");
        inbox.open(Folder.READ_ONLY);
        Message messages[] = inbox.getMessages();
        for (Message message : messages) {
            System.out.println(message);
        }
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (MessagingException e) {
        e.printStackTrace();
        System.exit(2);
    }

Here I know that the line props.setProperty("mail.store.socketFactory.class",
"com.imap.DummySSLSocketFactory");
is not implemented properly, because I don’t know how can I use it wit imaps..

And the DummyTrustManager:

package com.imap;

import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class DummyTrustManager implements X509TrustManager {

  public void checkClientTrusted(X509Certificate[] cert, String authType) throws CertificateException {

      // everything is trusted

  }

  public void checkServerTrusted(X509Certificate[] cert, String authType) throws CertificateException {

      // everything is trusted

  }

  public X509Certificate[] getAcceptedIssuers() {

      return new X509Certificate[0];

  }

} 

And the DummySoketSSLFactory:

  package com.imap;

  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.Socket;
  import javax.net.SocketFactory;
  import javax.net.ssl.*;

  public class DummySSLSocketFactory extends SSLSocketFactory {

      private SSLSocketFactory factory;

      public DummySSLSocketFactory() {

          try {

              SSLContext sslcontext = SSLContext.getInstance("TLS");

              sslcontext.init(null,

                                   new TrustManager[] { new DummyTrustManager() },

                                   null);

              factory = (SSLSocketFactory)sslcontext.getSocketFactory();

          } catch(Exception ex) {

          }

      }

      public static SocketFactory getDefault() {

          return new DummySSLSocketFactory();

      }

      public Socket createSocket() throws IOException {

          return factory.createSocket();

      }

      public Socket createSocket(Socket socket, String s, int i, boolean flag)

                                  throws IOException {

          return factory.createSocket(socket, s, i, flag);

      }

      public Socket createSocket(InetAddress inaddr, int i,

                                  InetAddress inaddr1, int j) throws IOException {

          return factory.createSocket(inaddr, i, inaddr1, j);

      }

      public Socket createSocket(InetAddress inaddr, int i)

                                  throws IOException {

          return factory.createSocket(inaddr, i);
}

      public Socket createSocket(String s, int i, InetAddress inaddr, int j)

                                  throws IOException {

          return factory.createSocket(s, i, inaddr, j);

      }

      public Socket createSocket(String s, int i) throws IOException {

          return factory.createSocket(s, i);

      }

      public String[] getDefaultCipherSuites() {

          return factory.getDefaultCipherSuites();

      }

      public String[] getSupportedCipherSuites() {

          return factory.getSupportedCipherSuites();

      }

  }

The dummy classes are from http://www.anddev.org/advanced-tutorials-f21/javamail-and-android-little-excursus-t3093.html

Please help me to get this work

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:54:23+00:00Added an answer on May 20, 2026 at 10:54 am

    The easiest solution is to create a self signing certificate. Example here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read and write from serial using events/interrupts. Currently, I have it
I want to read line n1->n2 from file foo.c into the current buffer. I
I want to read UTF-8 input in Perl, no matter if it comes from
I have used an open source code from CodeProject to read email from incoming
I want to parse some emails from a user 's inbox but when I
as im using different email clients to read/send my mails i want to setup
I want to read the contents of a URL but don't want to hang
I want to read all items of a feed in C#. The solutions I've
I want to read an specific xml node and its value for example <customers>
I want to read an xml file, apply a transform, then write to another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.