20.2. 電子メールの受信
EJB を使用する場合は、MDB (メッセージ駆動型 Bean) を使って電子メールを受信することができます。JBoss は JCA アダプタ (
mail-ra.rar) を提供していますが、以下のように mail-ra.rar を設定することも可能です。
@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());
}
}
受信されたメッセージは
onMessage(Message message) を呼び出します。 ほとんどの Seam アノテーションは MDB の内側で動作しますが、 永続コンテキストにはアクセスしないでください。