1

I need to develop an IMAP poller which pings an email server every few seconds and fetches every new email which arrives.

I've done it once for another application, but there I used an inbound mail channel from Spring Integration.

I just started "playing" with Play, and am not sure what the best way to achieve this is. I know that JavaMail already offers the possibility to fetch mails, but I am not sure how to actually package this. Should this be a separate module, a separate plugin, a service, or sth?

Should the polling functionality be implemented as a job?

NOTE: It is a web application BTW, although the description above may suggest it is not.

Preslav Rachev
  • 3,983
  • 6
  • 39
  • 63

2 Answers2

2

There are a few options to solve this:

1) Use java in a Job to poll the IMAP server at regular intervals

documentation on creating a Job is available and is pretty straight forward, just setup the job to run every minute or 5 minutes and then add the code to actually check for new emails.

http://www.playframework.org/documentation/1.2.4/jobs

If you're looking for how to check for new emails on IMAP then have a look through stack exchange there. For example, to poll gmail check out this question: Getting mail from GMail into Java application using IMAP

2) Use camel module to poll IMAP server with a custom route/processor

This is a heavyweight solution and only recommended if you want to make use of other features of Apache Camel.

The module is available here: http://www.playframework.org/modules/camel

Using camel to poll for IMAP messages is fairly easy once you get your head around how to use camel, the specific info for the IMAP route is here: http://camel.apache.org/mail.html

Community
  • 1
  • 1
grahamrb
  • 2,159
  • 2
  • 15
  • 22
0

In my opinion you shouldn't use Play at all for this — if I understand your requirements correctly. Play is a web framework intended to handle HTTP requests. Your requirements say nothing about HTTP at all, so a large part of Play! would be useless.

You could use Play's server runtime and Job (and cron) architecture to run this, but you would be misusing the facilities of the framework for something for which they were never intended. You may also be inheriting requirements from Play that you wouldn't ever actually need for an application/service like the one you want to build (for example the Python runtime).

I think you should not use Play for this, but rather create this as a simple, straight-forward Java application using Spring. With Spring's scheduling capabilities you can just as easily implement what you want.

Naturally, when you intend to build a web front-end on top of this in the future, that would make it a completely different story.

tmbrggmn
  • 8,680
  • 10
  • 35
  • 44