Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javax.mail.NoSuchProviderException: No provider for imaps

843834May 6 2009 — edited May 6 2009
This code connects to an mail Store over imaps. I'm using MailSSLSocketFactory to bypass cert verification for SSL connections.
    public static void getMailboxInfo()
            throws javax.mail.NoSuchProviderException, MessagingException, IOException, GeneralSecurityException {
        // setup mail server
        MailSSLSocketFactory sf = new MailSSLSocketFactory();
        sf.setTrustAllHosts(true);

        // set system properties
        Properties mailProps = System.getProperties();
        mailProps.put("mail.imaps.ssl.socketFactory", sf);

        mailProps.put("mail.store.protocol", "imaps");
        mailProps.put("mail.imaps.host", "host");
        mailProps.put("mail.imaps.port", "993");


        // get session
        //Session session = Session.getDefaultInstance(mailProps);
        mailProps.setProperty("mail.imaps.sasl.authorizationid", "user@domain.com");
        Session session = Session.getInstance(mailProps, new SASLMasqueradeAuthenticator("user", "pass"));
        session.setDebug(true);
        Store srcStore;
        srcStore = session.getStore();
        srcStore.connect();

    }

    private static class SASLMasqueradeAuthenticator extends Authenticator {

        String authcid, authcpass;

        public SASLMasqueradeAuthenticator(String adminusername, String adminpassword) {
            authcid = adminusername;
            authcpass = adminpassword;
        }

        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(authcid, authcpass);
        }
    }
I'm able to connect successfully when I run this code from the command line, but when I call this method from a struts application I'm all of a sudden getting errors.
  

javax.mail.NoSuchProviderException: No provider for imaps
	javax.mail.Session.getProvider(Session.java:460)
	javax.mail.Session.getStore(Session.java:535)
	javax.mail.Session.getStore(Session.java:515)
	javax.mail.Session.getStore(Session.java:501)
	quota.db.QuotaDB.getMailboxInfo(QuotaDB.java:202)
	quota.db.QuotaDB.getQuotaInfo(QuotaDB.java:124)
	quota.actions.GetQuotaInfoAction.execute(GetQuotaInfoAction.java:81)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
	org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
	org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
	org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
so something seems to be different between running this code from the command line in a test program, and calling this method from a tomcat webapp, not sure how to fix. I'm using mail.jar 1.4. Any advice appreciated.

Edited by: qt4x11 on May 6, 2009 10:35 AM

Edited by: qt4x11 on May 6, 2009 10:36 AM

Edited by: qt4x11 on May 6, 2009 10:36 AM

Edited by: qt4x11 on May 6, 2009 10:41 AM

Edited by: qt4x11 on May 6, 2009 10:42 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2009
Added on May 6 2009
1 comment
2,124 views