In one project, we needed a list of allowed email addresses that were allowed to send mail for one environment (QA), so various different parties involved in the project could test the application without the risk of any mail being sent to our clients' clients (end users) .
There was too much work to change all the code blocks that performed the distribution, so I implemented my own extender for the main class of the mail plug-in (grails.plugin.mail.MailMessageBuilder), which took the list of allowed email addresses from the application configuration and redefined the method. which resolved addresses before sending mail (toDestinationAddresses). Then I replaced the factory (plugin) method that MailMessageBuilders creates, so it created my own collectors using the Groovy metaClass in the Grails boot file.
It was a clean, non-intrusive fix, and it worked great.
heikkim
source share