Simple SMTP server for alias based forwarding

emailmail-forwardingpostfixsmtp

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 "foo@myserver.com mrfoo@gmail.com".
  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.

Best Answer

  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: mrfoo@gmail.com
    bar: mrbar@gmail.com
    

    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.

Related Topic