Membuat mailserver di ubuntu 8.4 menggunakan postfix+courier+mysql+squirrelmail

Kali akan saya tuliskan cara pembuatan mailserver, tapi tidak seperti tutorial terdahulu yang menggunakan dovecot dan user mail server berdasarkan user yang ada dalam linux box. Kali ini user dapat ditambahkan secara biasa tanpa harus menambahkan terlebih dahulu user kedalam linux box, karena user akan ditambahkan/dicatat dalam database mysql.

1. Masuk sebagai root didalam shell

  • sudo -s

2. Install paket-paket aplikasi yang diperlukan

  • apt-get install postfix postfix-tls postfix-mysql postfix-doc mysql-client-5.0 mysql-server-5.0 courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2 libsasl2-modules libsasl2-modules-sql openssl amavisd-new spamassassin clamav clamav-daemon zoo unzip lha squirrelmail phpmyadmin telnet bind9

3. Membuat user, tabel di database mysql

  • mysql -u root -p
    • masukkan password mysql anda
  • buat database ‘mail’
    • create database mail;
  • buat user yang akan mengakses database
    • CREATE USER 'adminemail'@'localhost' identified by ‘password_anda’;
  • masuk kedalam database mail untuk membuat tabel
    • use mail;
    • CREATE TABLE domains (
      domain varchar(50) NOT NULL,
      PRIMARY KEY (domain) )
      TYPE=MyISAM;
    • CREATE TABLE forwardings (
      source varchar(80) NOT NULL,
      destination TEXT NOT NULL,
      PRIMARY KEY (source) )
      TYPE=MyISAM;
    • CREATE TABLE users (
      email varchar(80) NOT NULL,
      password varchar(20) NOT NULL,
      PRIMARY KEY (email) )
      TYPE=MyISAM;
  • berikan grant pada user yang akan mengakses database mail
    • grant all on mail.* to ‘adminemail’@’localhost’;

4. Buat file-file baru yang akan digunakan postfix untuk merujuk ke database mysql(saya menggunakan aplikasi gedit)

  • gedit /etc/postfix/mysql-virtual_domains.cf

    • masukkan baris dibawah ini kedalam file yang anda buat(harap disesuaikan dengan user/password di mysql anda tadi)
      • user = adminemail
        password = password_anda
        dbname = mail
        table = domains
        select_field = ‘virtual’
        where_field = domain
        hosts = 127.0.0.1
    • save lalu tutup gedit.
  • gedit /etc/postfix/mysql-virtual_forwardings.cf

    • masukkan baris dibawah ini kedalam file yang anda buat(harap disesuaikan dengan user/password di mysql anda tadi)
      • user = adminemail
        password = password_anda
        dbname = mail
        table = forwardings
        select_field = destination
        where_field = source
        hosts = 127.0.0.1
    • save lalu tutup gedit.
  • gedit /etc/postfix/mysql-virtual_mailboxes.cf

    • masukkan baris dibawah ini kedalam file yang anda buat(harap disesuaikan dengan user/password di mysql anda tadi)
      • user = adminemail
        password = password_anda
        dbname = mail
        table = users
        select_field = CONCAT(SUBSTRING_INDEX(email,’@’,-1),’/’,SUBSTRING_INDEX(email,’@’,1),’/’)
        where_field = email
        hosts = 127.0.0.1
    • save lalu tutup gedit.
  • gedit /etc/postfix/mysql-virtual_email2email.cf

    • masukkan baris dibawah ini kedalam file yang anda buat(harap disesuaikan dengan user/password di mysql anda tadi)
      • user = adminemail
        password = password_anda
        dbname = mail
        table = users
        select_field = email
        where_field = email
        hosts = 127.0.0.1
  • demi keamanan lakukan command berikut
    • chown root:postfix /etc/postfix/mysql-virtual_*.cf
    • chmod u=rw,g=r,o= /etc/postfix/mysql-virtual_*.cf

5. Membuat user sebagai administrator dalam mail server

  • groupadd -g 5000 mail-admin
  • useradd -g mail-admin -u 5000 mail-admin -d /home/mail -m
  • mkdir /home/mail
  • chown -R mail-admin:mail-admin /home/mail
  • chmod -R u=rwx,g=,o= /home/mail

6. Mensetting postfix agar dapat berjalan sebagai SMTP server(edit file /etc/postfix/main.cf)

  • gedit /etc/postfix/main.cf
  • sesuaikan isi file dengan baris dibawah ini:
    • inet_interfaces = all
      myhostname = mail.ikaruga.net
      mydestination = (kosongkan saja, untuk virtual domain nantinya)
      mynetworks = ikaruga.et (nama domain anda)
      virtual_alias_domains =
      virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_forwardings.cf mysql:/etc/postfix/mysql-virtual_email2email.cf
      virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains.cf
      virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailboxes.cf
      virtual_mailbox_base = /home/mail
      virtual_uid_maps = static:5000
      virtual_gid_maps = static:5000
      smtpd_sasl_auth_enable = yes
      broken_sasl_auth_clients = yes
      smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
      smtpd_use_tls = yes
      smtpd_tls_cert_file = /etc/postfix/smtpd.cert
      smtpd_tls_key_file = /etc/postfix/smtpd.key
  • Test SMTP server
    • /etc/init.d/postfix restart
    • postfix check

      • jika tidak ada pesan error berarti konfigurasi benar&berhasil.
      • jika ada pesan error, coba anda ulangi lagi proses konfigurasinya.
    • telnet localhost 25
      • jika ada tampilan seperti dibawah maka postfix sudah berjalan dengan lancar
        • Trying 127.0.0.1…
          Connected to localhost.localdomain.
          Escape character is ‘^]’.
          220 mail.ikaruga.net ESMTP Postfix (ubuntu)
    • sekarang keluar dari sesi telnet
      • tekan CTRL+] untuk keluar dari sesi telnet

6. Aktifkan fasiltasi AUTH-SMTP(edit file /etc/postfix/sasl/smtpd.conf)

  • gedit /etc/postfix/sasl/smtpd.conf
  • isi file dengan baris berikut ini
    pwcheck_method: auxprop
    auxprop_plugin: sql
    mech_list: plain login cram-md5 digest-md5
    sql_engine: mysql
    sql_hostnames: 127.0.0.1
    sql_user: adminemail
    sql_passwd: password_anda
    sql_database: mail
    sql_select: select password from users where email=’%u@%r’
    log_level: 7
  • chown root:postfix /etc/postfix/sasl/smtpd.conf
  • chmod u=rw,g=r,o= /etc/postfix/sasl/smtpd.conf
  • buat certificate untuk meng-encrypt trafik SMTP
    • openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 365 -x509
  • chown root:postfix /etc/postfix/smtpd.*
  • chmod u=rw,g=r,o= /etc/postfix/smtpd.*

7. Mensetting courier sebagai server POP3/IMAP

  • gedit /etc/courier/authdaemonrc

    • ubah parameter authmodulelist menjadi
      • authmodulelist=”authmysql”
  • gedit /etc/courier/authmysqlrc

    • ubah beberapa parameter menjadi seperti baris-baris dibawah(dalam langkah ini anda harus extra hati-hati, jangan menggunakan tombol SPACE untuk memisahkan parameter dengan nilai yang dikandungnya, tapi gunakan tombol TAB)
      • MYSQL_SERVER localhost
        MYSQL_USERNAME adminemail
        MYSQL_PASSWORD password_anda
        MYSQL_PORT 0
        MYSQL_DATABASE mail
        MYSQL_USER_TABLE users
        #MYSQL_CRYPT_PWFIELD (jadikan sebagai komentar)
        MYSQL_CLEAR_PWFIELD password
        MYSQL_UID_FIELD 5000
        MYSQL_GID_FIELD 5000
        MYSQL_LOGIN_FIELD email
        MYSQL_HOME_FIELD “/home/mail”
        MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,’@’,-1),’/’,SUBSTRING_INDEX(email,’@’,1),’/’)
        #MYSQL_NAME_FIELD (jadikan sebagai komentar)
  • Test konfigurasi….
    • /etc/init.d/courier-authdaemon restart

      • jika tidak ada pesan error berarti konfigurasi benar&berhasil.
      • jika ada pesan error, coba anda ulangi lagi proses konfigurasinya.
    • telnet localhost 110
      Trying 127.0.0.1…
      Connected to localhost.
      Escape character is ‘^]’.
      +OK Hello there.
    • jika muncul tampilan seperti diatas, courier-authdaemon telah berjalan dengan lancar

8.Melakukan test untuk semua konfigurasi sebelumnya

  • Membuat virtual user di mysql
    • mysql -u adminemail -p mail
      masukkan password_anda
    • INSERT INTO domains(domain) VALUES ('ikaruga.net');
    • INSERT INTO users(email,password) VALUES ('admin@ikaruga.net','admin');
    • INSERT INTO users(email,password) VALUES ('user@ikaruga.net','user');
  • Menambahkan MX record
    • gedit /etc/bind/db.ikaruga.net
    • @ IN MX 5 mail.ikaruga.net.
      mail IN A 10.29.7.4
    • IP-Address 10.29.7.4 hanya sebagai contoh, sesuaikan dengan keperluan anda.
    • telnet localhost 25

      • Trying 127.0.0.1…
        Connected to localhost.
        Escape character is ‘^]’.
        220 mail.ikaruga.net ESMTP Postfix (ubuntu)
      • secara interaktif, lakukan command dibawah
        • anda : ehlo virtual.tes
          server : 250-mail.ikaruga.net
          250-PIPELINING
          250-SIZE 10240000
          250-VRFY
          250-ETRN
          250-STARTTLS
          250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5
          250-AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5
          250-ENHANCEDSTATUSCODES
          250-8BITMIME
          250 DSN
          anda : mail from:admin@ikaruga.net
          server : 250 OK
          anda : rcpt to:user@ikaruga.net
          server : 250 OK
          anda : data
          server :
          354 End data with .
          anda : Subject: Welcome
          welcome to squirrelmail world
          . (titik)
          server :
          250 Ok: queued as ABC1D1C123
          anda : quit
          server :
          221 BYE
      • jika ada seperti respon diatas, maka email dari admin@ikaruga.net sudah masuk kedalam antrian smtp untuk dikirim ke user@ikaruga.net, tidak percaya?! lakukan command berikut
        • tail -f /var/log/mail.info
        • maka akan terlihat :
          Sep 4 08:24:13 ikaruga imapd: LOGIN, user=admin@ikaruga.net, ip=[::ffff:127.0.0.1], port=[35948], protocol=IMAP
          Sep 4 08:24:13 ikaruga imapd: LOGOUT, user=admin@ikaruga.net, ip=[::ffff:127.0.0.1], headers=0, body=769, rcvd=79, sent=1222, time=0
          Sep 4 08:27:03 ikaruga postfix/anvil[13834]: statistics: max connection rate 1/60s for (smtp:127.0.0.1) at Sep 4 08:23:43
          Sep 4 08:27:03 ikaruga postfix/anvil[13834]: statistics: max connection count 1 for (smtp:127.0.0.1) at Sep 4 08:23:43
          Sep 4 08:27:03 ikaruga postfix/anvil[13834]: statistics: max cache size 1 at Sep 4 08:23:43
          Sep 4 09:56:35 ikaruga postfix/smtpd[17725]: connect from localhost[127.0.0.1]
          Sep 4 09:56:42 ikaruga postfix/smtpd[17725]: disconnect from localhost[127.0.0.1]
          Sep 4 09:58:01 ikaruga postfix/smtpd[17725]: connect from localhost[127.0.0.1]
          Sep 4 10:03:07 ikaruga postfix/smtpd[17725]: timeout after EHLO from localhost[127.0.0.1]
          Sep 4 10:03:07 ikaruga postfix/smtpd[17725]: disconnect from localhost[127.0.0.1]
          Sep 4 10:06:27 ikaruga postfix/anvil[17727]: statistics: max connection rate 1/60s for (smtp:127.0.0.1) at Sep 4 09:56:35
          Sep 4 10:06:27 ikaruga postfix/anvil[17727]: statistics: max connection count 1 for (smtp:127.0.0.1) at Sep 4 09:56:35
          Sep 4 10:06:27 ikaruga postfix/anvil[17727]: statistics: max cache size 1 at Sep 4 09:56:35
        • jika anda melihat “status=sent (delivered to maildir)” maka e-mail sudah terkirim
        • cek folder user e-mail
          • find /home/mail
          • /home/mail/
            /home/mail/ikaruga.net
            /home/mail/ikaruga.net
            /home/mail/ikaruga.net/user/cur
            /home/mail/ikaruga.net/user/new
            /home/mail/ikaruga.net/user/new/1170803794.V805I1c1fbM98807.ikaruga
            /home/mail/ikaruga.net/user/new/1170803833.V805I1c1feM87660.ikaruga
            /home/mail/ikaruga.net/user/tmp

9.Konfigurasi squirrelmail

  • squirrelmail-configure
    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Main Menu –
      1. Organization Preferences
      2. Server Settings
      3. Folder Defaults
      4. General Options
      5. Themes
      6. Address Books
      7. Message of the Day (MOTD)
      8. Plugins
      9. Database
      10. LanguagesD. Set pre-defined settings for specific IMAP servers

      C Turn color on
      S Save data
      Q Quit

      Command >>

    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Main Menu –
      1. Organization Preferences
      2. Server Settings
      3. Folder Defaults
      4. General Options
      5. Themes
      6. Address Books
      7. Message of the Day (MOTD)
      8. Plugins
      9. Database
      10. LanguagesD. Set pre-defined settings for specific IMAP servers

      C Turn color on
      S Save data
      Q Quit

      Command >> 2

    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Server SettingsGeneral
      ——-
      1. Domain : trim(implode(”, file(’/etc/’.(file_exists(’/etc/mailname’)?’mail’:’host’).’name’)))
      2. Invert Time : false
      3. Sendmail or SMTP : SMTP

      A. Update IMAP Settings : localhost:143
      B. Update SMTP Settings : localhost:25

      R Return to Main Menu
      C Turn color on
      S Save data
      Q Quit

      Command >> A

    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Server SettingsGeneral
      ——-
      1. Domain : trim(implode(”, file(’/etc/’.(file_exists(’/etc/mailname’)?’mail’:’host’).’name’)))
      2. Invert Time : false
      3. Sendmail or SMTP : SMTP

      IMAP Settings
      ————–
      4. IMAP Server : localhost
      5. IMAP Port : 143
      6. Authentication type : login
      7. Secure IMAP (TLS) : false
      8. Server software : courier
      9. Delimiter : .

      B. Update SMTP Settings : localhost:25
      H. Hide IMAP Server Settings

      R Return to Main Menu
      C Turn color on
      S Save data
      Q Quit

      Command >> 7

    • TLS (Transport Layer Security) encrypts the traffic between server and client.
      If you’re familiar with SSL, you get the idea.
      To use this feature, your IMAP server must offer TLS
      capability, plus PHP 4.3.x with OpenSSL support.
      Note that the ‘STARTTLS’ command is not supported; the server must
      have a dedicated port listening for TLS connections.If your IMAP server is localhost, you can safely disable this.
      If it is remote, you may wish to seriously consider enabling this.
      Enable TLS (y/n) [n]: n
    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Server SettingsGeneral
      ——-
      1. Domain : trim(implode(”, file(’/etc/’.(file_exists(’/etc/mailname’)?’mail’:’host’).’name’)))
      2. Invert Time : false
      3. Sendmail or SMTP : SMTP

      IMAP Settings
      ————–
      4. IMAP Server : localhost
      5. IMAP Port : 143
      6. Authentication type : login
      7. Secure IMAP (TLS) : false
      8. Server software : courier
      9. Delimiter : .

      B. Update SMTP Settings : localhost:25
      H. Hide IMAP Server Settings

      R Return to Main Menu
      C Turn color on
      S Save data
      Q Quit

      Command >> 8

    • Each IMAP server has its own quirks. As much as we tried to stick
      to standards, it doesn’t help much if the IMAP server doesn’t follow
      the same principles. We have made some work-arounds for some of
      these servers. If you would like to use them, please select your
      IMAP server. If you do not wish to use these work-arounds, you can
      set this to “other”, and none will be used.
      bincimap = Binc IMAP server
      courier = Courier IMAP server
      cyrus = Cyrus IMAP server
      dovecot = Dovecot Secure IMAP server
      exchange = Microsoft Exchange IMAP server
      hmailserver = hMailServer
      macosx = Mac OS X Mailserver
      mercury32 = Mercury/32
      uw = University of Washington’s IMAP server
      other = Not one of the above servers
      [courier]: courier
    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Server SettingsGeneral
      ——-
      1. Domain : trim(implode(”, file(’/etc/’.(file_exists(’/etc/mailname’)?’mail’:’host’).’name’)))
      2. Invert Time : false
      3. Sendmail or SMTP : SMTP

      IMAP Settings
      ————–
      4. IMAP Server : localhost
      5. IMAP Port : 143
      6. Authentication type : login
      7. Secure IMAP (TLS) : false
      8. Server software : courier
      9. Delimiter : .

      B. Update SMTP Settings : localhost:25
      H. Hide IMAP Server Settings

      R Return to Main Menu
      C Turn color on
      S Save data
      Q Quit

      Command >> s

    • tekan sembarang tombol
    • SquirrelMail Configuration : Read: config.php (1.4.0)
      ———————————————————
      Server SettingsGeneral
      ——-
      1. Domain : trim(implode(”, file(’/etc/’.(file_exists(’/etc/mailname’)?’mail’:’host’).’name’)))
      2. Invert Time : false
      3. Sendmail or SMTP : SMTP

      IMAP Settings
      ————–
      4. IMAP Server : localhost
      5. IMAP Port : 143
      6. Authentication type : login
      7. Secure IMAP (TLS) : false
      8. Server software : courier
      9. Delimiter : .

      B. Update SMTP Settings : localhost:25
      H. Hide IMAP Server Settings

      R Return to Main Menu
      C Turn color on
      S Save data
      Q Quit

      Command >> q

    • selesai

10. Membuat squirrelmail menjadi virtualhost

  • gedit /etc/apache2/sites-available/squirrelmail.conf
  • isi baris-baris berikut kedalam file:
    • NameVirtualHost 127.0.0.1:80

      ServerAdmin admin@ikaruga.netDocumentRoot /usr/share/squirrelmail

      Options FollowSymLinks
      AllowOverride None

      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all

       

    • save, tutup gedit
  • buat symbolic link
    • /etc/apache2/sites-available/squirrelmail.conf /etc/apache2/sites-enabled/001squirrelmail.conf
  • cek konfigurasi apache
    • apache2ctl configtest
    • jika muncul
      • Syntax OK
    • restart apache dengan command
      • apache2ctl restart

4 thoughts on “Membuat mailserver di ubuntu 8.4 menggunakan postfix+courier+mysql+squirrelmail

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s