If you use Enterprise JavaBeans (EJB), you can use a MDB (Message Driven Bean) to receive email. JBoss provides a JCA adaptor (mail-ra.rar). You can configure mail-ra.rar 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());
}
}
@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());
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Each message received calls onMessage(Message message). Most Seam annotations work inside a MDB, but you must not access the persistence context.
We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.
About Red Hat
We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.