If you are using EJB then you can use a MDB (Message Driven Bean) to receive email. Seam comes with an improved version of mail-ra.rar as distributed in JBoss AS; until the improvements make there way into a released version of JBoss AS, replacing the default rar with the one distributed with Seam is recommended.
You can configure it like this:
@MessageDriven(activationConfig={
@ActivationConfigProperty(propertyName="mailServer", propertyValue="localhost"),
@ActivationConfigProperty(propertyName="mailFolder", propertyValue="INBOX"),
@ActivationConfigProperty(propertyName="storeProtocol", propertyValue="pop3"),
@ActivationConfigProperty(propertyName="userName", propertyValue="seam"),
@ActivationConfigProperty(propertyName="password", propertyValue="seam")
})
@ResourceAdapter("mail-ra.rar")
@Name("mailListener")
public class MailListenerMDB implements MailListener {
@In(create=true)
private OrderProcessor orderProcessor;
public void onMessage(Message message) {
// Process the message
orderProcessor.process(message.getSubject());
}
}
Each message received will cause onMessage(Message message) to be called. Most seam annotations will work inside a MDB but you musn't access the persistence context.
You can find more information on the default mail-ra.rar at http://wiki.jboss.org/wiki/Wiki.jsp?page=InboundJavaMail. The version distributed with Seam also includes a debug property to enable JavaMail debugging, a flush property (by default true) to disable flushing a POP3 mailbox after successfullying delivering a message to your MDB and a port property to override the default TCP port. Beware that the api for this may be altered as changes make there way into JBoss AS.
If you aren't using JBoss AS you can still use mail-ra.rar (included with Seam in the mail directory), or you may find your application server includes a similar adapter.