I'm trying to send some queued mails when the session end (sort of an auto-send outbox pattern). I've tried a lot of options, but I always encounter problems. What I have:
A stateless bean (tried it with a javabean too) emailManager that sends the messages (javabean that contains a Renderer and the Message to be sent).
A stateful session bean (application scope) that stores the message queue, and sends everything out when needed. The emailManager is injected here.
What I tried until now:
Put the "sendQueuedMessages" method in the @Destroy or @Remove or @PreDestroy method. This doesn't work, because all of my injected variables (in the SFSB) are nulled by the time this method is called.
Put it in a method with @Observer("org.jboss.seam.preDestroyContext.SESSION"). This works better, but when the renderer renders the email template (multiple recipients with <ui:repeat>), the variable of the ui:repeat is filled with null values, so no luck there too.
In general, it seems like some things are already destroyed before the method is finished. I tried to use Asynchronous methods too, but they complain about the fact that ApplicationFactory is't initialized.