Postfix Forward Email To Another Email Account

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 as a mail forwarding domain. Open file, enter:
# vi /etc/postfix/
Make sure following two line exists:

virtual_alias_domains = 
# virtual_alias_domains = ..
virtual_alias_maps = hash:/etc/postfix/virtual

Open /etc/postfix/virtual file, enter:
# vi /etc/postfix/virtual
Forward email sent to to

You can also implement a catch-all address i.e. email sent to and should be forwarded to

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 file. Create /etc/postfix/virtual file as described. In other words do not list domain 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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 25 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
25 comments… add one
  • Shoaibi Jun 4, 2009 @ 10:24

    hmmm, nice…

  • noneck Jun 8, 2009 @ 23:27

    You could also leave the original address to keep a copy locally before forwarding, or have multiple email addresses seperated by commas.,

  • Gopal Aug 13, 2009 @ 9:13

    If I do,, the gets two copies of mail for every mail sent to

  • Mohammad Mateen Oct 30, 2009 @ 20:46

    How i can get this functionality ?
    Directory: /home/logmon Shell: /bin/bash
    Never logged in.
    Mail forwarded to “|/usr/local/bin/”
    No mail.
    No Plan.

    Plz help

  • Mohammad Mateen Oct 30, 2009 @ 20:47

    In simple words i want to forward a shell user email to some script

  • abi Jun 1, 2010 @ 5:38


    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?

    • Anatoliy Sep 8, 2010 @ 11:48

      Possible you forget about

      postmap /etc/postfix/virtual

      after changes to the virtual config

  • David Sep 21, 2011 @ 14:02

    I found a link with plenty of information on how to setup email forwarding on Ubuntu

    Forward All incoming email to single address

  • William Oct 14, 2011 @ 22:41

    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.


    • Frank Jun 19, 2013 @ 15:59

      can you specify this? How to set mailname?
      I found gmail is rejecting the forwarded email.

  • Manuel Dec 22, 2011 @ 10:18


    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?

  • A little help Sep 15, 2012 @ 3:41

    Here’s a little extra info that might help someone. I was going nuts looking for a way to forward any number of aliases to a single user based on regex. It’s similar to what this faq suggests and very easy, and it can be used for local and remote fowarding. Here’s the whole thing:

    1) Add a user (this will be your catch-all): useradd tiger

    2) Open your postfix config: vi /etc/postfix/

    3) Add the following to the bottom of the file:

    4) Create the virtual_config path: mkdir /etc/postfix/virtual_config

    5) Open the alias domains file: vi /etc/postfix/virtual_config/virtual_alias_domains

    6) Add all domains for which you wish to allow relays/forwarding to virtual_alias_domains file. Add one domain per line. For example, /etc/postfix/virtual_config/virtual_alias_domains:

    7) Open your alias maps file: vi /etc/postfix/virtual_config/virtual_alias_maps

    8) Add in your regex aliasing:

    9) Restart postfix (note: reload doesn’t always do what you want. Just restart): service postfix restart

    After that, all mail sent to your server and addressed to or will be forwarded to the user tiger on the local machine AND to

    I hope that saves someone some looking.

  • KV Nov 17, 2012 @ 16:11

    How can i forward from subdomain to main domian.

    Ex: all email from subdomain to


  • tony May 8, 2013 @ 15:06

    I did this, precisely as described, and now all mail to my server is rejected.

    cat /etc/postfix/virtual

    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.

    • tony May 8, 2013 @ 15:17

      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.

      • tony May 8, 2013 @ 15:27

        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.

  • Jeroen Jan 18, 2014 @ 14:16

    thank you for this nice tutorial. I have been able to set up postfix, but the mails don’t go through.
    I have made a catch all for my domain to my email address. I am trying to send mails to but they don’t appear in my mailbox.

    This is the log I get when I send a mail:
    I have replaced my own email address with ***MYMAIL*** for security reasons.

  • Eduardo Mozart de Oliveira Feb 24, 2014 @ 21:32

    There is really useful comments here and the post was amazing, thanks!
    If you followed the post, but still are not receiving e-mails, there is 2 things to check:

    Try running “postconf -n” in the terminal and check for both options that you set in (virtual_alias_domains and virtual_alias_maps)

    I checked that and it was still ok. But redirecting was not working.

    So, reading the postfix log (/var/log/ i see a warning:
    do not set mydestination and virtual_alias_domains the same. So, I edited mydestination and removed the domain and now it works.

    mydestination =,

    mydestination =

  • Arthur Nov 6, 2014 @ 12:56

    how do i now disable the forwading of mails from my domain( to another ( I activated it, now i no longer want to receive the mails in my yahoo account…

  • Alex Mar 29, 2016 @ 19:36

    Warning! I have encountered that with a default postfix configuration this will open your server for SPAM as it allows log in via unauthenticated locations. Dear author, please add a line on smtp restrictions!

    I have disabled SASL as it seems to be unneeded for forwarding only and disable the unauthenticated destinations for now as a first step.

    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

    Mar 29 19:23:10 planetsofa postfix/smtpd[11118]: warning: hostname does not resolve to address Name or service not known
    Mar 29 19:23:10 planetsofa postfix/smtpd[11118]: connect from unknown[]
    Mar 29 19:23:10 planetsofa postfix/smtpd[11118]: 5F14113E0005: client=unknown[]
    Mar 29 19:23:10 planetsofa postfix/cleanup[11122]: 5F14113E0005: message-id=

  • Rakesh Apr 7, 2016 @ 16:46

    i have configured mail server on two machine , machine-1 installed squirrelmail GUI and machine-2 is my server( postfix ,dovecot..etc) ,machine-1 is on public ip but machine-2 is on private ip because machine-2 have all user and mailbox to recive mail for security purpose, i am able to send mail but not receive mail, but if i am using only one machine then I’m successfully send and Receive mail , but my task is to setup mail server on 2 machine, so where is problem please reply me soon?

  • Krishnaprasad Feb 19, 2017 @ 4:24

    How can I forward email from to test@domain.local (which is email address of my internal/local server). Please help on this.

  • Nges Jun 16, 2017 @ 2:36

    I have followed the instructions above. And everything seems to work well. but I am using to receive the forwarded emails. For now, when I sent an email from to, this mail is sent from gmail but I can’t receive this email from which is aliased to

    I have checked the mailname as stated in one of the comments and it is good.

    Please any help on this ??


Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum