I've multiple virtual domain hosted on CentOS Postfix server. How do I forward selected virtual domain email to yahoo / gmail or other email account using Postfix email server?
Postfix can be configured as mail forwarding domains server using virtual_alias_maps settings. There are two type of configurations here.
Postfix Mail Forwarding Domains
This is useful if you do not have local mailboxes and server is not acting as MX backup (do not use the following if relay_domains sql map or virtual map is configured). The main purpose of these domains is to forward mail elsewhere. The following example shows how to set up cyberciti.com as a mail forwarding domain. Open main.cf file, enter:
# vi /etc/postfix/main.cf
Make sure following two line exists:
virtual_alias_domains = cyberciti.com # virtual_alias_domains = cyberciti.com example.com moredomains.com .. virtual_alias_maps = hash:/etc/postfix/virtual
Open /etc/postfix/virtual file, enter:
# vi /etc/postfix/virtual
Forward email sent to vivek@cyberciti.com to vivek@nixcraft.co.in:
vivek@cyberciti.com vivek@nixcraft.co.in
You can also implement a catch-all address i.e. email sent to tom@example.com and jerry@example.com should be forwarded to somewhereelse@another.domain.com
@example.com somewhereelse@another.domain.com
Save and close the file. Type the following command to restart postfix:
# postmap /etc/postfix/virtual
# service postfix reload
Postfix Mail Forwarding Domains For Backup MX Server
If your server is a backup mx with relay domain configured via mysql / ldap proxy map only add virtual_alias_maps = hash:/etc/postfix/virtual to main.cf file. Create /etc/postfix/virtual file as described. In other words do not list domain cyberciti.com in BOTH virtual_alias_domains and relay_domains. Use only one configuration option. Usually, relay_domains is configured for backup postfix MX servers.
Please note that you can also use procmail to forward email to another account.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 14 comments… read them below or add one }
hmmm, nice…
You could also leave the original address to keep a copy locally before forwarding, or have multiple email addresses seperated by commas.
vivek@cyberciti.com vivek@cyberciti.com, vivek@nixcraft.co.in
If I do vivek@cyberciti.com vivek@cyberciti.com, vivek@nixcraft.co.in, the vivek@nixcraft.co.in gets two copies of mail for every mail sent to vivek@cyberciti.com
How i can get this functionality ?
—————————————————-
Directory: /home/logmon Shell: /bin/bash
Never logged in.
Mail forwarded to “|/usr/local/bin/logmon.sh”
No mail.
No Plan.
—————————————————-
Plz help
In simple words i want to forward a shell user email to some script
Hi,
I have added the lines as per said and is working fine. Now i want remove the forwarding, so i removed the added lines and restarted the postfix. But still the script is running. can u tell a solution to fix it?
Possible you forget about
postmap /etc/postfix/virtual
after changes to the virtual config
Muchas Gracias!
Even though it is old, it worked perfectly for me – tip if you never used postfix: set the mailname to something useful or google will reject the emails.
William
Hi,
how can u configure postfix to send EVERY E-Mail to exactly ONE User on your machine?
for example:
I create a user “mailarchiv”.
Every mail which goes to the Server “mail-05″ should be saved in the Mailbox of “mailarchiv”.
Can u give me a hint?
You had it there, didn’t you?
@yourdomain.com mailarchiv@yourdomain.com
How can i forward from subdomain to main domian.
Ex: all email from subdomain @mail.maindomain.com to mail@maindomain.com
Thanks,
I did this, precisely as described, and now all mail to my server is rejected.
can’t get mail to any of the .org, .me, or .us, and can’t even get mail to the .info address.
All of these addresses were working before I did this.
Clearly, I want to send them all to one address, the .info address,
but now nothing gets through at all.
This is on Debian Squeeze, if relevant.
Also, blanking the virtual file and restarting postfix doesn’t put it back to working properly, either.
Following your instructions has hosed my mail server completely.
The e-mail addresses mentioned above are all in the mail db (mysql).
You do not mention whether this is relevant or not.
I was using them all as distinct mail address, and they were working, and I want to forward them all to one, now.
But if I can’t do that, at the very least, I’d like them to work as they before.
Currently none of them are working.
well, I seem to have got it working as it was again.
I had to empty the /etc/postfix/virtual,
remove the virtual_alias_domains line in my main.cnf
I ran sudo newaliases
and reloaded postfix
and it’s back to the previous “normal” state.
Clearly I’ll have to seek how to forward my mail properly elsewhere.