I often test my application with a copy of a live database, but I have to be careful not to take any action that causes the email to be sent to the user. I would like to have a way to configure spring, so when I am in dev or test mode, no email will be sent to real users. Ideally, I would like all emails to be sent to the user instead sent to a mailbox that I can check. And I don't want to change any code for this to happen, just the xml configuration files.
I already use PropertyPlaceholderConfigurer and read in different properties based files if I work in production, testing or dev mode. I am setting up JavaMailSenderImpl based on the values in the properties file. I also use SimpleMailMessage to create a template with a From address.
Ideally, there would be a way to rewrite the TO address of all outgoing emails to a test account if I am running in dev or test mode.
My first thought was to use a different SMTP server for dev and test. But then I will also have to manage another mail server, and he will need to configure it so that it does not send mail anywhere, but instead sends it to one mailbox. I do not want to add additional management requirements, if possible.
This may be the best solution, but there seems to be a way to intercept emails and change the recipient.
Has anyone dealt with this issue before? What solutions did you come up with?
source
share