I'm no expert in IronJacamar, which is what you'd need to get configured for an inbound adapter. My impression from reading the docs is that there are several layers of abstraction hiding a simple polling of the gmail IMAP service.
Good news is: you can do this easily yourself.
You have to configure a mail Session. I've ripped the following extract for standalone.xml
from a Wildfly example:
<subsystem xmlns="urn:jboss:domain:mail:1.0">
<mail-session jndi-name="java:/jboss/mail/MyGmail">
<imap-server address="example.com" port="432">
<login name="nobody" password="pass"/>
</imap-server>
</mail-session>
</subsystem>
If you've set it up like this, you can refer to your session as a Resource
:
@Stateless
public class PollingImapAccess {
@Resource(name = "java:/jboss/mail/MyGmail")
private Session session;
@Schedule(hour = "*")
public void init() {
try {
IMAPStore store = (IMAPStore) session.getStore();
if (!store.isConnected()) store.connect();
// grab your folders, scan for new messages
} catch (MessagingException ex) { /* handle exception */ }
}
}
This would cause the EJB container to wake up your bean every hour and connect to your gmail account. You can read more about timers in the tutorial.
I don't really appreciate that you have to burden your generic server config with your personal account information, you can fall back to the Session#getInstance() method:
Properties gmail = new Properties();
gmail.setProperty("mail.imaps.host", "imap.gmail.com");
gmail.setProperty("mail.imaps.port", "993");
Session session = Session.getInstance(gmail);
IMAPSSLStore mystore = (IMAPSSLstore) session.connect("me@gmail.com", "xxx");
The full list of settable properties is available in the javadoc.
In this case you don't need the @Resource
at all and can just wire up a new connection every time the method wakes up. Note that if plan to have any significant load on there, you probably want to cache that store object and only connect if the connection timed out.