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

  • SEARCH
  • Home
  • 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 4336914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:52:21+00:00 2026-05-21T10:52:21+00:00

I want to get my Exchange emails on android and for that I am

  • 0

I want to get my Exchange emails on android and for that I am using javamail api for android… it works great on gmail and yahoo using imap.
The problem is that my exchange server has self signed certificate so android don’t like this too much and I get 03-14 12:46:13.698: WARN/System.err(281): javax.mail.MessagingException: Not trusted server certificate;

I have seen this example: Sending Email in Android using JavaMail API without using the default/built-in app where somebody makes a send example over ssl.. I think I can use that JSSEProvider to accept my self signed certificate but I don’t know how can I use it.

Please help me!

  • 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-21T10:52:21+00:00Added an answer on May 21, 2026 at 10:52 am

    I have been having the same problem, and managed to get around it by configuring a trust manager as detailed at http://java.sun.com/products/javamail/javamail-1.4.2/SSLNOTES142.txt.

    What I did was create my own TrustManager:

    package com.myapp;
    import javax.net.ssl.X509TrustManager;
    import java.security.cert.X509Certificate;
    
    /**
     * DummyTrustManager - NOT SECURE
     */
    public class DummyTrustManager implements X509TrustManager {
    
        public void checkClientTrusted(X509Certificate[] cert, String authType) {
        // everything is trusted
        }
    
        public void checkServerTrusted(X509Certificate[] cert, String authType) {
        // everything is trusted
        }
    
        public X509Certificate[] getAcceptedIssuers() {
        return new X509Certificate[0];
        }
    }
    

    and use this in my own SSLSocketFactory:

    package com.myapp;
    
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.Socket;
    
    import javax.net.SocketFactory;
    import javax.net.ssl.*;
    
    
    /**
     * DummySSLSocketFactory
     */
    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) {
            // ignore
        }
        }
    
        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();
        }
    }
    

    To get this to work in javamail-android, you need to specify the new SSLSocketFactory before you get a Session instance:

        Properties props = new Properties();
        props.setProperty( "mail.imaps.socketFactory.class", "com.myapp.DummySSLSocketFactory" );
        session = Session.getDefaultInstance( props );
    

    The TrustManager which we defined now be used instead of the default one, and all certificates will be accepted.

    Obviously there are some security issues with blindly accepting all certificates, and I would suggest doing some checking in your TrustManager, otherwise you could open yourself up to all kinds of security issues (such as man-in-the-middle attacks). Also, I would only use this where you really have to: for example you say that GMail and Ymail is working, so I would not use this mechanism when connecting to those.

    I would put in an exception handler to catch the “Certificate not trusted” exception, and prompt the user to accept an untrusted certificate (with the necessary warning to only do this for servers that are absolutely trusted) before actually overriding the TrustManager.

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

Sidebar

Related Questions

I am trying to get emails from Microsoft Exchange server using EWSJ API which
I want to get tasks from an exchange server for sync in an android
I want to access a shared mailbox (NOT FOLDER) via Javamail API (1.4.5) using
I have a ruby client that connects to an exchange server using IMAP &
I want get all of the Geom objects that are related to a certain
I am using VS2010 - C# I want to build an exchange rate monitor
I want get the time used for a case so I can create an
I want get as much as possible from Redis + Hiredis + libevent. I'm
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it

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.