I just remembered that i'm using defaultInstance() for SMTP, or sending emails, but I'm developing software now to use IMAP to get/receive and parse emails.
How can I avoid using geronimo's version of java mail, and use another working version of java mail? the full stacktrace of the exception is below: org.apache.geronimo.javamail.util.InvalidCommandException: Unexpected command IMAP command error at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.receiveResponse(IMAPConnection.java:411) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.sendCommand(IMAPConnection.java:324) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.processLogin(IMAPConnection.java:567) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.login(IMAPConnection.java:500) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.protocolConnect(IMAPConnection.java:176) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.createPoolConnection(IMAPConnectionPool.java:211) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.protocolConnect(IMAPConnectionPool.java:177) at org.apache.geronimo.javamail.store.imap.IMAPStore.protocolConnect(IMAPStore.java:156) at javax.mail.Service.connect(Service.java:251) at javax.mail.Service.connect(Service.java:91) at utils.mail.EmailHandler.initialize(EmailHandler.java:62) at utils.mail.EmailStatelessBean.getEmails(EmailStatelessBean.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:128) at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:43) at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:64) at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176) at org.apache.openejb.monitoring.StatsInterceptor.AroundTimeout(StatsInterceptor.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138) at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:237) at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:189) at org.apache.openejb.core.timer.EjbTimerServiceImpl.ejbTimeout(EjbTimerServiceImpl.java:569) at org.apache.openejb.core.timer.EjbTimeoutJob.execute(EjbTimeoutJob.java:39) at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Dec 08, 2012 9:56:20 PM pf.ApplicationScopeBean log INFO: EmailStatelessBean.getEmails(): Error initializing GMAIL IMAP session. javax.mail.MessagingException: Not connected at org.apache.geronimo.javamail.store.imap.IMAPStore.checkConnectionStatus(IMAPStore.java:353) at org.apache.geronimo.javamail.store.imap.IMAPStore.getDefaultFolder(IMAPStore.java:204) at org.apache.geronimo.javamail.store.imap.IMAPStore.getFolder(IMAPStore.java:224) at utils.mail.EmailHandler.getMessagesFromFolder(EmailHandler.java:130) at utils.mail.EmailHandler.loadEmailsFromInbox(EmailHandler.java:113) at utils.mail.EmailStatelessBean.getEmails(EmailStatelessBean.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:128) at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:43) at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:64) at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176) at org.apache.openejb.monitoring.StatsInterceptor.AroundTimeout(StatsInterceptor.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138) at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:237) at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:189) at org.apache.openejb.core.timer.EjbTimerServiceImpl.ejbTimeout(EjbTimerServiceImpl.java:569) at org.apache.openejb.core.timer.EjbTimeoutJob.execute(EjbTimeoutJob.java:39) at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Dec 08, 2012 9:56:20 PM pf.ApplicationScopeBean log INFO: EmailStatelessBean.getEmails(): Error loading emails from Inbox Dec 08, 2012 9:58:00 PM pf.ApplicationScopeBean log INFO: EmailStatelessBean.getEmails(): invoked Sat Dec 08 21:58:00 EST 2012 org.apache.geronimo.javamail.util.InvalidCommandException: Unexpected command IMAP command error at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.receiveResponse(IMAPConnection.java:411) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.sendCommand(IMAPConnection.java:324) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.processLogin(IMAPConnection.java:567) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.login(IMAPConnection.java:500) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.protocolConnect(IMAPConnection.java:176) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.createPoolConnection(IMAPConnectionPool.java:211) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.protocolConnect(IMAPConnectionPool.java:177) at org.apache.geronimo.javamail.store.imap.IMAPStore.protocolConnect(IMAPStore.java:156) at javax.mail.Service.connect(Service.java:251) at javax.mail.Service.connect(Service.java:91) at utils.mail.EmailHandler.initialize(EmailHandler.java:62) at utils.mail.EmailStatelessBean.getEmails(EmailStatelessBean.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:128) at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:43) at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:64) at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176) at org.apache.openejb.monitoring.StatsInterceptor.AroundTimeout(StatsInterceptor.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163) at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138) at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:237) at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:189) at org.apache.openejb.core.timer.EjbTimerServiceImpl.ejbTimeout(EjbTimerServiceImpl.java:569) at org.apache.openejb.core.timer.EjbTimeoutJob.execute(EjbTimeoutJob.java:39) at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) On Sat, Dec 8, 2012 at 9:26 PM, Howard W. Smith, Jr. <smithh032...@gmail.com > wrote: > The code below works just fine in a @Stateless bean (which is invoked by > @Schedule), running on Glassfish3.1.2.2. > > props = System.getProperties(); > props.setProperty("mail.store.protocol", "imaps"); > //session = Session.getDefaultInstance(props, null); > session = Session.getInstance(props); > store = session.getStore("imaps"); > store.connect("imap.gmail.com", "usern...@gmail.com", > "password"); > > > I attempted the above code in TomEE 1.5.1, but the result was the > exception below. Does this exception mean that I have to Configure > Javamail as demonstrated at > http://tomee.apache.org/configuring-javamail.html, or does this mean > something else? > > > org.apache.geronimo.javamail.util.InvalidCommandException: Unexpected > command IMAP command error > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.receiveResponse(IMAPConnection.java:411) > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.sendCommand(IMAPConnection.java:324) > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.processLogin(IMAPConnection.java:567) > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.login(IMAPConnection.java:500) > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.protocolConnect(IMAPConnection.java:176) > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.createPoolConnection(IMAPConnectionPool.java:211) > at > org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.protocolConnect(IMAPConnectionPool.java:177) > at > org.apache.geronimo.javamail.store.imap.IMAPStore.protocolConnect(IMAPStore.java:156) > at javax.mail.Service.connect(Service.java:251) > at javax.mail.Service.connect(Service.java:91) > >