install postfix, dovecot, sasl, postfixadmin | ubuntu server 14.04

Posted by Achmad 'Rhoma' Fanani (kanny) on 4/22/2014 09:53:00 AM


ceritanya kita mau bikin mail server yg gampang di manage, bisa multi domain pula..
udah gitu bisa dibaca pake email client seperti Mozilla Thunderbird, outlok, dan sebangsanya...

terlebih dulu pastikan tidak ada masalah pada MX record domain kamu, seting hostname jg woke..
pastikan pula apache2, php5 & mysql server (LAMP) beserta pengikutnya udah jalan dg baik & benar..
pastikan juga php5-imap udah masuk dlm modul apache2...

ok, langsung ajah instal...
* install postfix
#apt-get install postfix sasl2-bin
jika ada pertanyaan, jawab sesuai kebutuhanmu.
disini kita pake




  • General type of mail configuration? Internet Site
  • System mail name? server1.example.com
  • (sesuaikan dg nama hostname kamu)

    selanjutnya kita bikin sertipikat.. kalo duit kamu banyak, beli sertipikat "resmi" juga bagus ;)

    mkdir /etc/postfix/ssl
    cd /etc/postfix/ssl/ openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024chmod 600 smtpd.key
    openssl req -new -key smtpd.key -out smtpd.csr
    openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
    openssl rsa -in smtpd.key -out smtpd.key.unencrypted
    mv -f smtpd.key.unencrypted smtpd.key
    openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
    * install Dovecot
    #apt-get install postfix-mysql dovecot-mysql dovecot-imapd postgrey

    jika diperlukan, bikin certificate untuk dovecot
    #openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/dovecot.pem -keyout /etc/ssl/private/dovecot.pem

    * install postfixadmin
    donlot file instaler postfixadmin terbaru (berextensi .deb) dr webnya postfixadmin
    mainkan file .deb itu...
    #dpkg -i postfixadmin_2.3.7-1_all.deb
    -----
    file konfigurasi..
    file konfig berikut sekedar sepenggal kisah dr experimen ane.. sesuaikan dg kebutuhan hidup kamu masing2... :)

    *) config postfixadmin

    /var/www/postfixadmin/config.inc.php

    $CONF['configured'] = true;
    $CONF['postfix_admin_url'] = 'http://yourdomain.tld/postfixadmin';
    
    $CONF['database_type'] = 'mysql';
    $CONF['database_host'] = 'localhost';
    $CONF['database_user'] = 'postfixadmin';
    $CONF['database_password'] = 'rahasia!';
    $CONF['database_name'] = 'postfixadmin';
    
    $CONF['domain_path'] = 'NO';
    $CONF['domain_in_mailbox'] = 'YES';
    $CONF['encrypt'] = 'md5crypt';

    selanjutnya buka broser andalan kamu, menujulah ke 
    http://mail.example.com/postfixadmin/setup.php
     dijalankan dia akan memeriksa apakah kebutuhan kamu sudah layak atau belom, jika belom ya penuhi dulu kebutuhan untuk hidup postfixadmin.
    kalo udah oke, ikuti langkah berikutnya yakni bikin password setup
    selanjutnya copas hash string itu ketempatnya /var/www/postfixadmin/config.inc.php
    $CONF['setup_password'] = '...a long hash string...';


    *) config Dovecot

     Create a User to Handle Virtual Mail Directories

    useradd -r -u 150 -g mail -d /var/vmail -s /sbin/nologin -c "Virtual maildir handler" vmail

    mkdir /var/vmail

    chmod 770 /var/vmail

    chown vmail:mail /var/vmail

    /etc/dovecot/conf.d/auth-sql.conf.ext 

    # Look up user passwords from a SQL database as

    # defined in /etc/dovecot/dovecot-sql.conf.ext

    passdb {

      driver = sql

      args = /etc/dovecot/dovecot-sql.conf.ext

    }

    # Look up user information from a SQL database as

    # defined in /etc/dovecot/dovecot-sql.conf.ext

    userdb {
      driver = sql
      args = /etc/dovecot/dovecot-sql.conf.ext
    }


    /etc/dovecot/dovecot-sql.conf.ext
    driver = mysql
    connect = host=localhost dbname=postfixadmin user=postfixadmin password=rahasia!
    default_pass_scheme = MD5-CRYPT

    password_query = \

      SELECT username as user, password, '/var/vmail/%d/%n' as userdb_home, \

      'maildir:/var/vmail/%d/%n' as userdb_mail, 150 as userdb_uid, 8 as userdb_gid \

      FROM mailbox WHERE username = '%u' AND active = '1'



    user_query = \

      SELECT '/var/vmail/%d/%n' as home, 'maildir:/var/vmail/%d/%n' as mail, \

      150 AS uid, 8 AS gid, concat('dirsize:storage=', quota) AS quota \

      FROM mailbox WHERE username = '%u' AND active = '1'

    /etc/dovecot/conf.d/10-auth.conf 
    disable_plaintext_auth = yes
    auth_mechanisms = plain login
    !include auth-sql.conf.ext

    /etc/dovecot/conf.d/10-mail.conf
    mail_location = maildir:/var/vmail/%d/%n
    mail_uid = vmail
    mail_gid = mail
    first_valid_uid = 150
    last_valid_uid = 150

    /etc/dovecot/conf.d/10-ssl.conf

    ssl = yes

    ssl_cert = </etc/ssl/certs/dovecot.pem

    ssl_key = </etc/ssl/private/dovecot.pem


    /etc/dovecot/conf.d/10-master.conf 

    service auth {

      # auth_socket_path points to this userdb socket by default. It's typically

      # used by dovecot-lda, doveadm, possibly imap process, etc. Its default

      # permissions make it readable only by root, but you may need to relax these

      # permissions. Users that have access to this socket are able to get a list

      # of all usernames and get results of everyone's userdb lookups.

      unix_listener auth-userdb {

       mode = 0600

        user = vmail
        group = mail
      }
      unix_listener /var/spool/postfix/private/auth {
        mode = 0660
        # Assuming the default Postfix user and group
        user = postfix
        group = postfix       
      }

    /etc/dovecot/conf.d/15-lda.conf
    postmaster_address = postmaster@example.com


    You'll want to change the Dovecot configuration to be accessible to both dovecot and vmail users:

    1
    2
    chown -R vmail:dovecot /etc/dovecot
    chmod -R o-rwx /etc/dovecot

    A final note on Dovecot: it only creates a user's mail directory when mail is first delivered to that virtual user. So creating a user in Postfix Admin will not result in the immediate creation of a mail directory under /var/vmail, and that's just fine.


    *) Config postfix



    /etc/postfix/mysql_virtual_alias_domainaliases_maps.cf

    1
    2
    3
    4
    5
    6
    7
    8
    user = mail
    password = mailpassword
    hosts = 127.0.0.1
    dbname = mail
    query = SELECT goto FROM alias,alias_domain
      WHERE alias_domain.alias_domain = '%d'
      AND alias.address=concat('%u', '@', alias_domain.target_domain)
      AND alias.active = 1

    /etc/postfix/mysql_virtual_alias_maps.cf

    1
    2
    3
    4
    5
    6
    7
    8
    user = mail
    password = mailpassword
    hosts = 127.0.0.1
    dbname = mail
    table = alias
    select_field = goto
    where_field = address
    additional_conditions = and active = '1'

    /etc/postfix/mysql_virtual_domains_maps.cf

    1
    2
    3
    4
    5
    6
    7
    8
    user = mail
    password = mailpassword
    hosts = 127.0.0.1
    dbname = mail
    table = domain
    select_field = domain
    where_field = domain
    additional_conditions = and backupmx = '0' and active = '1'

    /etc/postfix/mysql_virtual_mailbox_domainaliases_maps.cf

    1
    2
    3
    4
    5
    6
    7
    8
    user = mail
    password = mailpassword
    hosts = 127.0.0.1
    dbname = mail
    query = SELECT maildir FROM mailbox, alias_domain
      WHERE alias_domain.alias_domain = '%d'
      AND mailbox.username=concat('%u', '@', alias_domain.target_domain )
      AND mailbox.active = 1

    /etc/postfix/mysql_virtual_mailbox_maps.cf
    1
    2
    3
    4
    5
    6
    7
    8
    user = mail
    password = mailpassword
    hosts = 127.0.0.1
    dbname = mail
    table = mailbox
    select_field = CONCAT(domain, '/', local_part)
    where_field = username
    additional_conditions = and active = '1'
    Now create the file /etc/postfix/header_checks, which will contain some directives to remove certain headers when relaying mail. This improves privacy for the sending users by such things as stripping the original IP address and mail software identifiers, for example. This file will be referenced in the main Postfix configuration:

    1
    2
    3
    4
    5
    6
    /^Received:/                 IGNORE
    /^User-Agent:/               IGNORE
    /^X-Mailer:/                 IGNORE
    /^X-Originating-IP:/         IGNORE
    /^x-cr-[a-z]*:/              IGNORE
    /^Thread-Index:/             IGNORE

    /etc/postfix/main.cf  (komplit)
    # See /usr/share/postfix/main.cf.dist for a commented, more complete version
    # The first text sent to a connecting process.
    smtpd_banner = $myhostname ESMTP $mail_name
    biff = no
    append_dot_mydomain = no
    readme_directory = no # TLS parameters
    smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt smtpd_tls_key_file = /etc/postfix/ssl/smtpd.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
    myhostname = mail.mydom.com
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    myorigin = /etc/mailname
    mydestination =
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
    home_mailbox = Maildir/
    smtpd_tls_loglevel = 1
    smtpd_tls_received_header = yes
    smtpd_tls_session_cache_timeout = 3600s
    tls_random_source = dev:/dev/urandom
    smtp_use_tls = yes

    smtp_tls_note_starttls_offer = yes
    permit_mynetworks reject_unauth_destination
    mailbox_command =
    inet_protocols = ipv4

    broken_sasl_auth_clients = yes
    smtpd_recipient_restrictions =
      permit_mynetworks,
      permit_sasl_authenticated,
      reject_non_fqdn_hostname,
      reject_non_fqdn_sender,
      reject_non_fqdn_recipient,
      reject_unauth_destination,
      reject_unauth_pipelining,
      reject_invalid_hostname
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_local_domain = $myhostname
    smtpd_sasl_security_options = noanonymous

    smtpd_sasl_type = dovecot
    smtpd_sasl_path = private/auth

    virtual_uid_maps = static:150
    virtual_gid_maps = static:8
    virtual_mailbox_base = /var/vmail

    virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
    #virtual_mailbox_base = /home/vmail
    virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
    virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf


    virtual_transport = dovecot
    dovecot_destination_recipient_limit = 1

    /etc/postfix/master.cf (komplit)

    #

    # # Postfix master process configuration file. For details on the format # of the file, see the master(5) manual page (command: "man 5 master"). # # Do not forget to execute "postfix reload" after editing this file. # # ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ========================================================================== smtp inet n - - - - smtpd #smtp inet n - - - 1 postscreen #smtpd pass - - - - - smtpd #dnsblog unix - - - - 0 dnsblog #tlsproxy unix - - - - 0 tlsproxy submission inet n - - - - smtpd # -o syslog_name=postfix/submission # -o smtpd_tls_security_level=encrypt # -o smtpd_sasl_auth_enable=yes # -o smtpd_client_restrictions=permit_sasl_authenticated,reject # -o milter_macro_daemon_name=ORIGINATING #smtps inet n - - - - smtpd # -o syslog_name=postfix/smtps # -o smtpd_tls_wrappermode=yes # -o smtpd_sasl_auth_enable=yes # -o smtpd_client_restrictions=permit_sasl_authenticated,reject # -o milter_macro_daemon_name=ORIGINATING #628 inet n - - - - qmqpd pickup fifo n - - 60 1 pickup cleanup unix n - - - 0 cleanup qmgr fifo n - n 300 1 qmgr #qmgr fifo n - n 300 1 oqmgr tlsmgr unix - - - 1000? 1 tlsmgr rewrite unix - - - - - trivial-rewrite bounce unix - - - - 0 bounce defer unix - - - - 0 bounce trace unix - - - - 0 bounce verify unix - - - - 1 verify flush unix n - - 1000? 0 flush proxymap unix - - n - - proxymap proxywrite unix - - n - 1 proxymap smtp unix - - - - - smtp relay unix - - - - - smtp # -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 showq unix n - - - - showq error unix - - - - - error retry unix - - - - - error discard unix - - - - - discard local unix - n n - - local virtual unix - n n - - virtual lmtp unix - - - - - lmtp anvil unix - - - - 1 anvil scache unix - - - - 1 scache # # ==================================================================== # Interfaces to non-Postfix software. Be sure to examine the manual # pages of the non-Postfix software to find out what options it wants. # # Many of the following services use the Postfix pipe(8) delivery # agent. See the pipe(8) man page for information about ${recipient} # and other message envelope options. # ==================================================================== # # maildrop. See the Postfix MAILDROP_README file for details. # Also specify in main.cf: maildrop_destination_recipient_limit=1 # maildrop unix - n n - - pipe flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient} # # ==================================================================== # # Recent Cyrus versions can use the existing "lmtp" master.cf entry. # # Specify in cyrus.conf: # lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4 # # Specify in main.cf one or more of the following: # mailbox_transport = lmtp:inet:localhost # virtual_transport = lmtp:inet:localhost # # ==================================================================== # # Cyrus 2.1.5 (Amos Gouaux) # Also specify in main.cf: cyrus_destination_recipient_limit=1 # #cyrus unix - n n - - pipe # user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user} # # ==================================================================== # Old example of delivery via Cyrus. # #old-cyrus unix - n n - - pipe # flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user} # # ==================================================================== # # See the Postfix UUCP_README file for configuration details. # uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) # # Other external delivery methods. # ifmail unix - n n - - pipe flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) bsmtp unix - n n - - pipe flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient scalemail-backend unix - n n - 2 pipe flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension} mailman unix - n n - - pipe flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user} # Integration with Dovecot - hand mail over to it for local delivery, and # run the process under the vmail user and mail group. dovecot unix - n n - - pipe flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/dovecot-lda -d $(recipient)

    restart service
    service postfix restart

    service dovecot restart


    udah gitu aja, kalo bingung di gogling aja ya..
    hehe....

    coba: telnet localhost 25
    hasilnya gimanna..

    jangan lupa pantengin log kalo ada eror biar tau..
    tail -f /var/log/mail.log  | ccze

    sdikit clue, kalo ada error spt ini
     Error: Invalid user settings. Refer to server log for more information

    cara mengatasinya, tambahkan mantra berikut pada /etc/dovecot/conf.d/10-mail.conf
    namespace inbox {
         inbox = yes 
    }

    selamat mencoba.. :)




    sumber reperensi n copas dr:
    http://rimuhosting.com/knowledgebase/linux/mail/postfixadmin
    https://www.exratione.com/2012/05/a-mailserver-on-ubuntu-1204-postfix-dovecot-mysql/
    http://jonsview.com/how-to-setup-email-services-on-ubuntu-using-postfix-tlssasl-and-dovecot


    Nama Anda
    New Johny WussUpdated: 4/22/2014 09:53:00 AM

    0 komentar:

    CB