Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a SMTP server that will just be used to forward a few email addresses. Two requirements:

  1. Easy to install and configure on Ubuntu.
  2. Has an aliases file that is easy to automatically add to. Ideally, it would be a text file consisting of rows like "".
  3. (Ideally) Can be easily configured to only accept mail from specific hosts.

I've been trying Postfix, but I'm getting bogged down in error messages like Recipient address rejected: User unknown in virtual alias table and Recipient address rejected: User unknown in local recipient table. So I wonder if there is an easier solution.

share|improve this question
Please elaborate point 3 and I can complete my answer. – John Siu Jan 22 '13 at 4:59
Oh, point 3: I only want to relay mail for one specific host, not the whole internet. I guess I could firewall it with a whitelist, but a setting in the SMTP server itself is a bit more convenient. – Steve Bennett Jan 22 '13 at 5:32
If you are worry about spam, my config file already has basic spam filtering. I can add in the single host (incomming) restriction if that is what you want. – John Siu Jan 22 '13 at 5:34
up vote 2 down vote accepted
  1. Use Postfix

    On ubuntu, do following

    apt-get install postfix

    I am doing the exact same thing with my vps email setup. check up my blog post Tiny VPS Postfix. I am copying the example below


    # See /usr/share/postfix/ for a commented, more complete version
    # Debian specific:  Specifying a file name will cause the first
    # line of that file to be used as the name.  The Debian default
    # is /etc/mailname.
    #myorigin = /etc/mailname
    smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
    biff = no
    # appending .domain is the MUA's job.
    append_dot_mydomain = no
    # Uncomment the next line to generate "delayed mail" warnings
    #delay_warning_time = 4h
    readme_directory = no
    # TLS parameters
    smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
    smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
    # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
    # information on enabling SSL in the smtp client.
    myhostname = <YOUR HOSTNAME>
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    myorigin = /etc/mailname
    mydestination = <YOUR DOMAIN NAME>, localhost.domain, localhost
    relayhost =
    mynetworks = [::ffff:]/104 [::1]/128
    mailbox_command = procmail -a "$EXTENSION"
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    smtpd_recipient_restrictions =

    Remeber to change <YOUR HOSTNAME> and <YOUR DOMAIN NAME>

  2. Alias file

    Your /etc/aliases file should be like the following


    The left hand side should have no domain name, only username. The domain is control by your postfix configuration. then do following

    cd /etc
    postalias aliases
    service postfix restart
  3. Single host restriction

    To allow only email from a single(or a few) host, I am going to use a very lazy way to do it.

    Assuming the IP of the allowed incoming host has IP, add it to mynetworks

    mynetworks = [::ffff:]/104 [::1]/128

    Change smtpd_recipient_restrictions to following

    smtpd_recipient_restrictions =

    Postfix only (and always) accept email from host(s) listed in mynetworks. And reject everything else.

  4. DNS Configuration

    Remember to setup MX record and spf record.

share|improve this answer
Wow, much more comprehensive than I was expecting. I think the part I was failing on was regenerating the hash. (Why doesn't postfix just check file dates and regenerate as needed?) Now stuck on "network unreachable" to gmail server - even though I can telnet to it on port 25 from that host. – Steve Bennett Jan 22 '13 at 6:01
3 completed. network unreachable? Can your server ping Which gmail host you telnet to? – John Siu Jan 22 '13 at 6:03
Hmm, seems to be ok - I've had at least one test message go through :) One last question though - is there a way to make the aliases file automatically regenerate? – Steve Bennett Jan 22 '13 at 6:25
No. But if you want to be lazy, you can modify the postfix startup script to include the alias regen command in it. As you do need to restart postfix anyway. – John Siu Jan 22 '13 at 6:29
OK, if you want to be even lazier, you can create a cron job to do it. But that seems overkill :p – John Siu Jan 22 '13 at 6:42

I use Postfix in a similar fashion to forward to another server. Using the three configuration options, but for your config there is an easier way.

  • relay_recipient_maps = ldap:/etc/postfix/
  • transport_maps = ldap:/etc/postfix/
  • relay_domains = ldap:/etc/postfix/

One of my LDAP files looks like this for querying an LDAP source on Zimbra...

query_filter = (&(|(zimbraMailDeliveryAddress=%s)(zimbraMailAlias=%s)(zimbraMailCatchAllAddress=%s))(zimbraMailStatus=enabled))
result_attribute = zimbraMailDeliveryAddress,zimbraMailAlias
version = 3
ldap_cache = yes
ldap_cache_expiry = 600
ldap_cache_size = 64256
bind = yes
bind_dn = uid=[valid login],cn=[valid cn],cn=[valid cn]
bind_pw = [a valid password]
timeout = 30

However, based on what you are looking for, it would be easier to keep the information in local hash tables that can be used for this purpose. The only thing you need to remember is that when you make changes to the files, you need to re-run postmap to build the postfix friendly hash table.

  • relay_recipient_maps = hash:/etc/postfix/relay_recipients_maps
  • relay_domains =
  • transport_maps = hash:/etc/postfix/transport_maps

You will need to create a text file in the above location with the following entry pairs: {[email address] OK} OK OK OK

Run postmap on the file above to generate the actual hash file which is then created in the same folder as relay_recipients_maps.db. Postfix will now check this file for valid recipients for delivery.

You then need to tell Postfix where to send email for this domain when it is received. Doing the same thing with /etc/postfix/transport_maps file, you can enter vaild pairs which are the domain the email is going to and the host to forward it on to.

Hopefully this helps point you the right direction. There is alot more information on how to do these types of config files on the internet and others can even use DB's for lookups for these configuations options.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.