Oct/071
Postfix: SMTP Relay – quick ‘n dirty redirect ALL mails
A software in a developement environment is sending mails to productive mail adresses of several domains. Due to some tests the software generates thousands of mails which would flood the mailboxes. The software has no debug-mode which rewrites the reciep mail adress. The only chance is to add a special smtp server. Therefore we need to create a special smtp-relay which rewrites the receptor adress (“To:”) in the mail header to a special mail address. I’ve used a small SuSE Linux machine with postfix to realize this.
Note: I’m not very expierienced with postfix administration so there could be a better solution. It took some time to find this solution, I tried out several things. The virtual tables seemed to be a possible solution.
Here the steps I made quick ‘n dirty:
# Create (or edit if already exists) the virtual regex configuration file
vi /etc/postfix/virtual-regexp
# Add the following:# Rewrite all addresses to debug-mails@domain.de
/.+@.+/ debug-mails@domain.de# Now save the file and close vi
# Build the postfix DB file
postmap /etc/postfix/virtual-regexp# Edit postfix main configuration
vi /etc/postfix/main.cf
# Add sth. to the virtual_maps value that it looks like this:
virtual_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp# Save and close the file
# Reload postfix
/etc/init.d/postfix reload
Now we have a SMTP relay which forwards ALL incoming mails to the specified mail address. Test it! You can use any mail address as reciep, it will be rewritten.
echo “Testmail” | mail -s “Test” test@my-test-domain.com







