Q. How do I setup cacth-all email accounts under Postfix MTA? For example if an email send to me@domain.com, info@you.com and sales@you.com, should be sent to the same email address.

This is useful if anyone of user mistypes an email address when they send it to me, or just guesses at a valid email address, then they will likely get an error message from my server such as user / email mail box does not exist. So I wish to set up a “catch all” address

A. Mapping is done using /etc/postfix/virtual file.
# vi /etc/postfix/virtual
Append code as follows, replacing domain and emailusername with actual values:
@yourdomain.com emailusername

Save and close the file. Run following command:
# postmap /etc/postfix/virtual

Also make sure you have following line in /etc/postfix/main.cf file:
virtual_alias_maps = hash:/etc/postfix/virtual

If you just added above, line reload postfix:
# service postfix reload

Caution: if you set up a catch-all email address, you will likely receive more unsolicited (spam) email.


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

🐧 14 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
14 comments… add one
  • omar Aug 6, 2008 @ 9:02

    I need to do something similar. I need the domain to forward emails to email@otherhost.com when emails sent to email@myhost.com. Is there a way to do that?
    Thank you !

  • 🐧 nixCraft Aug 6, 2008 @ 9:15

    create .forward file in users home directory (for email@myhost.com user) and put email ID email@otherhost.com.

  • sureshkumar Feb 26, 2009 @ 12:23

    HI Vivek how can i Add multiple users for SMTP auth on postfix
    /etc/postfix/sasl_passwd
    [smtp.gmail.com]:587 example@domain.com:passswd
    [smtp.gmail.com]:587 example1@domain.com:passswd1
    but are not support gmail ….. can you help me please ….
    in the virtual concepts support these concept………..am waiting for your reply…..

  • Rob Mar 13, 2009 @ 16:39

    Bump on sureshkumar’s question

  • 🐧 nixCraft Mar 13, 2009 @ 17:24

    I don’t think so it is possible to use multiple gmail account. sasl_passwd totally depends upon first part (hostname) to determine correct username:password when there are multiple entries in sasl_passwd. You need unique hostname for multiple entries:

    foo.com              you@foo.com
    bar.com              you@bar.com
    foo.in                  you@foo.in

    However, you can use something as follows in /etc/postfix/sasl_passwd:

    user1@gmail.com           username1:password1
    user2@gmail.com           username2:password2

    Next set, /etc/postfix/sender_relay:

    user1@gmail.com           [smtp.gmail.com]:587
    user2@gmail.com           [smtp.gmail.com]:587

    Setup main.cf as follows:

    smtp_sender_dependent_authentication = yes
    sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    relayhost = [smtp.gmail.com]:587
  • Bob Jul 13, 2009 @ 14:35

    What about if you have multiple domains and you all emails sent to bob@* to go to the bob user name but everything else to go to the jim username. How do you do that?

  • sumit Sep 11, 2009 @ 20:29

    I want to configure postfix virtual so that all emails goes to one address.

    I can’t specify individual domain in virtual as I don’t know. Can anyone help me on this?

  • Nd May 31, 2010 @ 19:11

    Possible solution for those looking to catch everything (any domain):

    Edit /etc/postfix/master.cf, change the ‘smtp’ declaration to:
    smtp inet n – – – – smtpd -o content_filter=verp

    And insert:
    verp unix – n n – 10 pipe user=USER_HERE argv=PATH_HERE

    Where ‘verp’ can be whatever you like, e.g. myfilter, mybouncehandler, etc.

  • mark mason Feb 23, 2011 @ 6:15

    I want to allow for email forwarding to my customers so we all have ourcityname.com as our email addresses that forward to yahoo or gmail accounts. I can do this by hand on cpanel but I need a solution with an api to set up email forwards. Anybody know of a product?

  • Sohail Dec 24, 2012 @ 15:20

    Hello,
    I want to dynamically create different mail id’s (user1@abc.com, user2@abc.com,….)for a user(abc) but not different users and not even aliases. whenever a user sends an email to newly generated mail id(user1@abc.com) it sholud get delivered to user(abc)’s mail box. Can anyone solve this up?

  • omer Jan 13, 2014 @ 16:19

    Thank you brother. İt’s so good.

  • Apoorva Sep 9, 2015 @ 8:56

    i want to do email id mapping under one domain.

    for example : xyz@shine.com & abc@shine.com are two email id’s.
    i want to map both of them under sky@shine.com.

    as if anybody sends email on sky@shine.com,it shoud go to both xyz@shine.com & abc@shine.com.

  • Mihai Dec 10, 2015 @ 20:49

    Hello, How can I redirect only or non-existent mailboxes on the server? if I have other maiboxes from the same domain, I dont want the catchall to be applied….
    and…
    How can I silent redirect and in the same time to send back a bounce message?

    Thank you!

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