Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-6480

JavaMail IMAP SSL sessions not working properly, e.g. Reading GMail IMAP accounts

    Details

    • Steps to Reproduce:
      Hide

      Create the config as described above then try and read your inbox like this:

      ...
      @Resource(mappedName = "java:jboss/mail/Default")
      private Session mySession;
      ...

      public List<String> poll() throws Exception
      {
      long start = System.currentTimeMillis();
      List<String> list = new ArrayList<String>();

      Store store = null;
      Folder inbox = null;
      try {
      // List all messages in the INBOX
      store = mySession.getStore();
      store.connect();

      inbox = store.getFolder("INBOX");

      inbox.open(Folder.READ_WRITE);

      Message[] messages = inbox.getMessages();
      for (Message m : messages)

      { System.out.println("Message subject:" + m.getSubject()); list.add(m.getSubject()); }

      }
      catch (NoSuchProviderException ex)

      { ex.printStackTrace(); System.out.println("Unable to connect to IMAP store. No provider, Java Mail session may not be configured correctly"); }

      catch (MessagingException ex)

      { ex.printStackTrace(); System.out.println("Error occured while processing messages in IMAP store:" + ex.getMessage()); }

      catch (Exception ex)

      { System.out.println("Unknown error occured while processing messages in IMAP store"); }

      finally {
      try {
      if (null != inbox)

      { inbox.close(true); }

      if (null != store)

      { store.close(); }

      }
      catch (Exception ex)

      { System.out.println("Unable to close IMAP store connection"); }

      }

      long end = System.currentTimeMillis();
      long diff = end - start;
      System.out.println("Found [" + list.size() + "] messages. In [" + diff + "] millis.");
      return list;
      }

      Show
      Create the config as described above then try and read your inbox like this: ... @Resource(mappedName = "java:jboss/mail/Default") private Session mySession; ... public List<String> poll() throws Exception { long start = System.currentTimeMillis(); List<String> list = new ArrayList<String>(); Store store = null; Folder inbox = null; try { // List all messages in the INBOX store = mySession.getStore(); store.connect(); inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); Message[] messages = inbox.getMessages(); for (Message m : messages) { System.out.println("Message subject:" + m.getSubject()); list.add(m.getSubject()); } } catch (NoSuchProviderException ex) { ex.printStackTrace(); System.out.println("Unable to connect to IMAP store. No provider, Java Mail session may not be configured correctly"); } catch (MessagingException ex) { ex.printStackTrace(); System.out.println("Error occured while processing messages in IMAP store:" + ex.getMessage()); } catch (Exception ex) { System.out.println("Unknown error occured while processing messages in IMAP store"); } finally { try { if (null != inbox) { inbox.close(true); } if (null != store) { store.close(); } } catch (Exception ex) { System.out.println("Unable to close IMAP store connection"); } } long end = System.currentTimeMillis(); long diff = end - start; System.out.println("Found [" + list.size() + "] messages. In [" + diff + "] millis."); return list; }
    • Estimated Difficulty:
      Low

      Description

      When I try and read my GMail (using the imap protocol) account INBOX using a JavaMail session from this config:

      ...
      <subsystem xmlns="urn:jboss:domain:mail:1.0">
      <mail-session jndi-name="java:jboss/mail/Default" debug="true" from="mygmailaccount">
      <smtp-server ssl="true" outbound-socket-binding-ref="mail-smtp">
      <login name="mygmailaccount" password="xxx"/>
      </smtp-server>
      <imap-server ssl="true" outbound-socket-binding-ref="mail-imap">
      <login name="mygmailaccount" password="xxx"/>
      </imap-server>
      </mail-session>
      </subsystem>
      ...

      ...
      <outbound-socket-binding name="mail-smtp">
      <remote-destination host="smtp.gmail.com" port="465"/>
      </outbound-socket-binding>
      <outbound-socket-binding name="mail-imap">
      <remote-destination host="imap.gmail.com" port="993"/>
      </outbound-socket-binding>
      ...

      I get the following error in the server logs: javax.mail.NoSuchProviderException: Invalid protocol: null

      Here the full stack trace:

      20:03:19,643 INFO [stdout] (http-/127.0.0.1:8080-1) DEBUG: JavaMail version 1.4.4
      20:03:19,668 INFO [stdout] (http-/127.0.0.1:8080-1) DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
      20:03:19,669 INFO [stdout] (http-/127.0.0.1:8080-1) DEBUG: Tables of loaded providers
      20:03:19,670 INFO [stdout] (http-/127.0.0.1:8080-1) DEBUG: Providers Listed By Class Name:

      {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}

      20:03:19,672 INFO [stdout] (http-/127.0.0.1:8080-1) DEBUG: Providers Listed By Protocol:

      {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}

      20:03:19,684 INFO [stdout] (http-/127.0.0.1:8080-1) DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
      20:03:19,700 ERROR [stderr] (http-/127.0.0.1:8080-1) javax.mail.NoSuchProviderException: Invalid protocol: null
      20:03:19,701 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.mail.Session.getProvider(Session.java:440)
      20:03:19,702 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.mail.Session.getStore(Session.java:539)
      20:03:19,702 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.mail.Session.getStore(Session.java:519)
      20:03:19,703 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.mail.Session.getStore(Session.java:505)
      20:03:19,703 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.jboss.as.quickstarts.mail.Email.poll(Email.java:96)
      20:03:19,703 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.jboss.as.quickstarts.mail.Email$Proxy$$$_WeldClientProxy.poll(Email$Proxy$$$_WeldClientProxy.java)
      20:03:19,704 ERROR [stderr] (http-/127.0.0.1:8080-1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      20:03:19,704 ERROR [stderr] (http-/127.0.0.1:8080-1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      20:03:19,704 ERROR [stderr] (http-/127.0.0.1:8080-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      20:03:19,704 ERROR [stderr] (http-/127.0.0.1:8080-1) at java.lang.reflect.Method.invoke(Method.java:601)
      20:03:19,705 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:735)
      20:03:19,705 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
      20:03:19,705 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:246)
      20:03:19,705 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.el.parser.AstValue.getValue(AstValue.java:159)
      20:03:19,706 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
      20:03:19,706 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
      20:03:19,706 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
      20:03:19,706 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
      20:03:19,707 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
      20:03:19,707 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
      20:03:19,707 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
      20:03:19,708 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
      20:03:19,708 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
      20:03:19,708 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
      20:03:19,708 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
      20:03:19,709 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
      20:03:19,709 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
      20:03:19,709 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
      20:03:19,709 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
      20:03:19,710 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
      20:03:19,710 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      20:03:19,710 ERROR [stderr] (http-/127.0.0.1:8080-1) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      20:03:19,711 ERROR [stderr] (http-/127.0.0.1:8080-1) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
      20:03:19,711 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
      20:03:19,711 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      20:03:19,712 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
      20:03:19,712 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
      20:03:19,712 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      20:03:19,713 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
      20:03:19,713 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      20:03:19,713 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:165)
      20:03:19,713 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
      20:03:19,714 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      20:03:19,714 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      20:03:19,714 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372)
      20:03:19,714 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
      20:03:19,715 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
      20:03:19,715 ERROR [stderr] (http-/127.0.0.1:8080-1) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
      20:03:19,715 ERROR [stderr] (http-/127.0.0.1:8080-1) at java.lang.Thread.run(Thread.java:722)

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                rschamm Rainer Schamm
                Reporter:
                rschamm Rainer Schamm
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: