Hal pertama yang perlu di sesuaikan adalah hostname
. Untuk mengganti hostname Debian edit file /etc/hostname
, untuk memudahkan di tutorial kali ini kita akan menggunakan hostname mail.jaranguda.com
root@mail:~# cat /etc/hostname mail.jaranguda.com
Versi Dovecot dan Postfix yang digunakan
Postfix 2.9.6
Dovecot 2.1.7
Upgrade software-software yang terinstall di Debian 7
apt-get clean all; apt-get update; apt-get upgrade
Install aplikasi yang dibutuhkan untuk instalasi Postfix, Dovecot dan MySQL
apt-get install dovecot-pop3d dovecot-sieve libsasl2-2 libsasl2-modules postfix postfix-mysql mysql-client mysql-server dovecot-common dovecot-imapd libsasl2-modules-sql sasl2-bin libpam-mysql openssl mailutils
bila diminta memasukkan password MySQL, buatlah password dengan kombinasi huruf angka, contoh
C25_-eRQKxb8xN9U-ReJ
Pada Package configuration -> Postfix configuration pilih Internet Site
Pada system mail name, isikan sesuai dengan hostname server
mail.jaranguda.com
Membuat database untuk User
login ke MySQL server
mysql -u root -p
password sama dengan password yang dibuat waktu instalasi, di contoh
C25_-eRQKxb8xN9U-ReJ
buat database dengan nama mail
CREATE DATABASE mail; USE mail;
tambah user baru, untuk mengelola database mail
CREATE USER 'dbmail'@'localhost' IDENTIFIED BY 'knn_o345345q_BD6TQ-'; GRANT ALL PRIVILEGES ON mail.* TO 'dbmail'@'localhost'; GRANT ALL PRIVILEGES ON mail.* TO 'dbmail'@'localhost.localdomain'; GRANT ALL PRIVILEGES ON mail.* TO 'dbmail'@'127.0.0.1'; FLUSH PRIVILEGES;
Buat table untuk mengelola domain
CREATE TABLE domains (domain varchar(60) NOT NULL, PRIMARY KEY (domain) );
Buat table untuk mengelola mail forwarding
CREATE TABLE forwardings (source varchar(80) NOT NULL, destination TEXT NOT NULL, PRIMARY KEY (source) );
Buat table untuk mengelola users (email account)
CREATE TABLE users (email varchar(100) NOT NULL, password varchar(20) NOT NULL, PRIMARY KEY (email) );
Buat table untuk mengelola transports
CREATE TABLE transport ( domain varchar(128) NOT NULL default '', transport varchar(128) NOT NULL default '', UNIQUE KEY domain (domain) );
setelah semua selesai sekarang close MySQL
quit;
Menghubungkan Postfix dengan MySQL
File konfigurasi postfix berada di folder
/etc/postfix/
Mapping virtual domain Postfix, buat file /etc/postfix/mysql-virtual_domains.cf tambahkan script dibawah ini
user = dbmail password = knn_on9_DLCNq_BD6TQ- dbname = mail query = SELECT domain AS virtual FROM domains WHERE domain='%s' hosts = 127.0.0.1
Buat file /etc/postfix/mysql-virtual_forwardings.cf tambahkan
user = dbmail password = knn_on9_DLCNq_BD6TQ- dbname = mail query = SELECT destination FROM forwardings WHERE source='%s' hosts = 127.0.0.1
Buat file /etc/postfix/mysql-virtual_mailboxes.cf tambahkan
user = dbmail password = knn_on9_DLCNq_BD6TQ- dbname = mail query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM users WHERE email='%s' hosts = 127.0.0.1
Buat file /etc/postfix/mysql-virtual_email2email.cf tambahkan
user = dbmail password = knn_on9_DLCNq_BD6TQ- dbname = mail query = SELECT email FROM users WHERE email='%s' hosts = 127.0.0.1
buat file /etc/postfix/mysql-virtual_email2email.cf
user = dbmail password = knn_on9_DLCNq_BD6TQ- dbname = mail query = SELECT email FROM users WHERE email='%s' hosts = 127.0.0.1
Ubah file permission mysql_virtual* agar bisa dibaca oleh postfix, dari sebelumnya
ls -la /etc/postfix/mysql-virtual_*.cf -rw-r--r-- 1 root root 143 Apr 7 07:57 mysql-virtual_domains.cf -rw-r--r-- 1 root root 141 Apr 7 07:59 mysql-virtual_forwardings.cf -rw-r--r-- 1 root root 197 Apr 7 08:00 mysql-virtual_mailboxes.cf
ubah dengan perintah
chgrp postfix /etc/postfix/mysql-virtual_*.cf
hasilnya
ls -la /etc/postfix/mysql-virtual_*.cf -rw-r--r-- 1 root postfix 143 Apr 7 07:57 /etc/postfix/mysql-virtual_domains.cf -rw-r--r-- 1 root postfix 141 Apr 7 07:59 /etc/postfix/mysql-virtual_forwardings.cf -rw-r--r-- 1 root postfix 197 Apr 7 08:00 /etc/postfix/mysql-virtual_mailboxes.cf
Buat group baru bernama vmail, untuk menghandle semua email, semua email akan disimpan disini
groupadd -g 5000 vmail useradd -g vmail -u 5000 vmail -d /home/vmail -m
Jalankan perintah dibawah ini, ganti mail.jaranguda.com dengan hostname servera anda
postconf -e 'myhostname = mail.jaranguda.com' postconf -e 'mydestination = mail.jaranguda.com, localhost, localhost.localdomain' postconf -e 'mynetworks = 127.0.0.0/8' postconf -e 'message_size_limit = 30720000' postconf -e 'virtual_alias_domains =' postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf' postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf' postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf' postconf -e 'virtual_mailbox_base = /home/vmail' postconf -e 'virtual_uid_maps = static:5000' postconf -e 'virtual_gid_maps = static:5000' postconf -e 'smtpd_sasl_auth_enable = yes' postconf -e 'broken_sasl_auth_clients = yes' postconf -e 'smtpd_sasl_authenticated_header = yes' postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination' postconf -e 'smtpd_use_tls = yes' postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert' postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key' postconf -e 'virtual_create_maildirsize = yes' postconf -e 'virtual_maildir_extended = yes' postconf -e 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps' postconf -e virtual_transport=dovecot postconf -e dovecot_destination_recipient_limit=1
Menghubungkan saslauthd dengan MySQL
Buat folder baru tempat menyimpan file saslauthd
mkdir -p /var/spool/postfix/var/run/saslauthd
buka file /etc/default/saslauthd ubah bagian
START=no OPTIONS="-c -m /var/run/saslauthd"
menjadi
START=yes OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"
Buat file /etc/pam.d/smtp tambahkan
auth required pam_mysql.so user=dbmail passwd=knn_on9_DLCNq_BD6TQ- host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 account sufficient pam_mysql.so user=dbmail passwd=knn_on9_DLCNq_BD6TQ- host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1
buat file /etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd mech_list: plain login allow_plaintext: true auxprop_plugin: mysql sql_hostnames: 127.0.0.1 sql_user: dbmail sql_passwd: knn_on9_DLCNq_BD6TQ- sql_database: mail sql_select: select password from users where email = '%u'
Ubah file permission SMTP
chmod o= /etc/pam.d/smtp chmod o= /etc/postfix/sasl/smtpd.conf
edit file /etc/postfix/master.cf, tambahkan dibagian paling bawah
dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient} 465 inet n - - - - smtpd
hapus isi file /etc/dovecot/dovecot.conf gantikan dengan
# 2.1.7: /tmp/dovecot.conf # OS: Linux 3.2.0-4-amd64 x86_64 Debian 7.4 ext4 auth_debug = yes auth_mechanisms = plain login log_timestamp = "%Y-%m-%d %H:%M:%S " mail_debug = yes mail_location = maildir:/home/vmail/%d/%n/Maildir namespace { inbox = yes location = prefix = INBOX. separator = . type = private } passdb { args = /etc/dovecot/dovecot-sql.conf driver = sql } protocols = imap pop3 service auth { unix_listener /var/spool/postfix/private/auth { group = postfix mode = 0660 user = postfix } unix_listener auth-master { mode = 0600 user = vmail } } ssl_cert = </etc/postfix/ssl.crt ssl_key = </etc/postfix/ssl.key userdb { args = uid=5000 gid=5000 home=/home/vmail/%d/%n allow_all_users=yes driver = static } protocol lda { auth_socket_path = /var/run/dovecot/auth-master log_path = /home/vmail/dovecot-deliver.log mail_plugins = sieve postmaster_address = postmaster@jaranguda.com } protocol pop3 { pop3_uidl_format = %08Xu%08Xv }
Generate SSL
openssl req -new -outform PEM -out ssl.crt -newkey rsa:2048 -nodes -keyout ssl.key -keyform PEM -days 365 -x509
buat file /etc/dovecot/dovecot-sql.conf
driver = mysql connect = host=127.0.0.1 dbname=mail user=dbmail password=knn_on9_DLCNq_BD6TQ- default_pass_scheme = CRYPT password_query = SELECT email as user, password FROM users WHERE email='%u';
Setelah semua selesai, sekarang restart postfix.
service postfix restart
Membuat email account
Login ke MySQL
mysql -u root -p use mail; INSERT INTO domains (domain) VALUES ('jaranguda.com'); INSERT INTO users (email, password) VALUES ('db80@jaranguda.com', ENCRYPT('db90x72134')); quit;
lalu coba mengirim email ke db80@jaranguda.com
root@mail:~# mailx db80@jaranguda.com Cc: Subject: Coba mail Server baru migrasi server dari dovecot 1.xx ke dovecot 2.x
seteleah selesai mengetik email anda tekan ctrl + d
, coba cek log, untuk mengetahui email anda terkirim atau tidak
Apr 8 04:01:37 mail dovecot: imap(db80@jaranguda.com): Disconnected: Logged out in=50 out=416 Apr 8 04:02:31 mail postfix/pickup[5230]: 5C42A404A7: uid=0 from=<root@mail.jaranguda.com> Apr 8 04:02:31 mail postfix/cleanup[5259]: 5C42A404A7: message-id=<20140408040231.5C42A404A7@mail.jaranguda.com>
sampai disini tutorial instalasi mail server di Debian 7, sudah selesai, bila ada pertanyaan silahkan buat komentar dibawah.