Postfix setup catch-all email accounts using /etc/postfix/virtual

Posted on in Categories , , , , , last updated July 6, 2007

Q. How do I setup cacth-all email accounts under Postfix MTA? For example if an email send to [email protected], [email protected] and [email protected], 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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

14 comment

  1. 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              [email protected]
    bar.com              [email protected]
    foo.in                  [email protected]

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

    [email protected]           username1:password1
    [email protected]           username2:password2

    Next set, /etc/postfix/sender_relay:

    [email protected]           [smtp.gmail.com]:587
    [email protected]           [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
  2. 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.

  3. 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?

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

  5. i want to do email id mapping under one domain.

    for example : [email protected] & [email protected] are two email id’s.
    i want to map both of them under [email protected].

    as if anybody sends email on [email protected],it shoud go to both [email protected] & [email protected].

  6. 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 Comment