I'd like to be able to test if my automatically sent mails are really sent, but I do not want these mails to leak to real world. Is there a way to configure my mail settings so that all mails sent from my test environment are automatically forwarded to a single mailbox?
I suppose I can configure addresses in my configuration, but if I replace every e-mail in my system with my test e-mail, I won't be able to clearly check if mails are really created correctly.
While testing, I might enter real world e-mail addresses, but I do not want to risk mails being sent to customers.
One way to safely isolate your test environment is to configure a mailserver that catches all mails from and to all domains, and puts them in one big inbox. If I configure that mailserver in my test environment, all mails are cought.
Many mailservers support this scenario. I used an open source one, hmailserver on an Azure VM. Installation steps:
Install it using default settings. Then configure it:
Create a domain anymail
Everything should work now. You should be able to configure anymail.yourregion.cloudapp.azure.com in your configuration, but also in your mail program (e.g. outlook). You can check that you can send mails from any sender to any recepient. Test that mails to your regular e-mail address don't arrive in your regular mailbox.
DIAGNOSTICS
While tweaking settings I often looked at status -> delivery queue. This queue is not automatically refreshed, so you need to refresh it manually. You may need to clear it while testing. (I often got into loops, resulting in many many messages.)