5

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 "[email protected] [email protected]".
  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.

3
  • Please elaborate point 3 and I can complete my answer.
    – John Siu
    Jan 22, 2013 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. Jan 22, 2013 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, 2013 at 5:34

2 Answers 2

5
  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

    /etc/postfix/main.cf

    # See /usr/share/postfix/main.cf.dist 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_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
    smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
    smtpd_use_tls=yes
    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 = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_command = procmail -a "$EXTENSION"
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    
    smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_invalid_hostname,
        reject_non_fqdn_hostname,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unknown_recipient_domain,
        reject_unlisted_recipient,
        reject_unauth_destination,
        reject_rbl_client cbl.abuseat.org,
        reject_rbl_client bl.spamcop.net,
        reject_rbl_client relays.mail-abuse.org,
        reject_rbl_client dnsbl.proxybl.org,
        reject_rbl_client truncate.gbudb.net,
        reject_rbl_client dnsbl.njabl.org,
        permit
    

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

  2. Alias file

    Your /etc/aliases file should be like the following

    foo: [email protected]
    bar: [email protected]
    

    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 192.168.1.100, add it to mynetworks

    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.100
    

    Change smtpd_recipient_restrictions to following

    smtpd_recipient_restrictions =
        permit_mynetworks,
        reject_unlisted_recipient
    

    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.

7
  • 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. Jan 22, 2013 at 6:01
  • 3 completed. network unreachable? Can your server ping 8.8.8.8? Which gmail host you telnet to?
    – John Siu
    Jan 22, 2013 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? Jan 22, 2013 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, 2013 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, 2013 at 6:42
1

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/ldap_relay_recipients_maps.cf
  • transport_maps = ldap:/etc/postfix/ldap_transport_maps.cf
  • relay_domains = ldap:/etc/postfix/ldap_relay_domains.cf

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

server_host=ldap://[mail.domain.com]:389
server_port=389
search_base=
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 = fwddomain.com
  • 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}

[email protected] OK
[email protected] OK
[email protected] 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.

fwddomain.com      smtp:mail.fwddomain.com

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .