[jboss-user] [Installation, Configuration & Deployment] - JavaMail recipient override?

sweetlandj do-not-reply at jboss.com
Tue Sep 15 15:59:02 EDT 2009


What I'm trying to do is implement a "recipient override" in the server mail configuration to protect against sending E-mails to customers when testing E-mail behavior in non-production environments.  I can do this easily with a custom session bean, but unfortunately Seam insists on using either java:/Mail or its own internal MailSession wrapper.  I would like to guarantee (as much as possible) that any E-mail sent from the system, however it is sent, is subject to this override.

One solution is to handle it at the OS level, i.e. configure mail-service.xml to point to localhost and configure the local mail server to forward everything to a specific set of addresses.  However, that does not prevent a developer from checking out code and executing it locally, and if they happen to have a local mail relay running then we are in trouble.  So out of the box I'd like the app server to be configured to redirect E-mails by default, and to explicitly disable this feature in production environments.

I've looked at the MailService MBean source code and it looks like I can override this class to accept a class name for some Session implementation, load that class from the configuration, and then pass the custom class to the Reference constructor.  If I created a Session decorator class that delegated all of the calls to the normal Session implementation except for getTransport; and then created a Transport decorator that delegates all of its calls to the normal Transport except for send() and sendMessages(), then I could intercept the message as it is sent and change the addresses before calling the same method on the delegate.

Does this sound like a viable approach?  Are there any easier/better ways to go about this?  Has anyone implement a similar override system another way?


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255395#4255395

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255395



More information about the jboss-user mailing list