< BACK

Redirect all email in your development environment

Quick post. Scenario: You have a Drupal site running on production and as you should be doing it, all the development is done in a different server but you use the database with all the real users and their emails. How can you prevent the real users from receiving all the emails?

In the drupal site you’ll need the mail_redirect module. Is really easy to install. Basically what it does is just redirect all email to a domain, so if you have luis@gmail.com you’ll redirect emails to luis@mydomain.com

The drupal module does it really good, but you still have a problem, you’ll probably want to read all those emails, right? Well, easy to do it, all you have to do is create the file:

$ sudo nano /etc/postfix/virtual

and add the following line:

@mydomain.com luis@myrealdomain.com

So basically a multiple redirection will happen. The drupal module will redirect all real email to users who probably doesn’t exist in your server, it will change the real domain to the domain you specify in configuration of the module. If you have billgates@microsoft and timcook@apple.com as your users, all email will go to billgates@mydomain.com and timcook@mydomain.com and those emails will be lost.

With postfix you redirect emails sent to any-user@mydomain.com to your real email address, luis@myrealdomain.com, this could be even an external domain, like @gmail.com

After that edit the file: /etc/postfix/main.cf as root and add the following:

virtual_alias_domains = mydomain.com
virtual_alias_maps = hash:/etc/postfix/virtual

Finally, just run as root

$ postmap /etc/postfix/virtual
$ service postfix reload

And test, you should receive all email from your site to the email you specified.

One more thing, is probably not a good idea to redirect all email to your main email address, you’ll get lots of spam.


Share this: