Postfix - Build native Postix smtp server dengan support submission authentication

Pada langkah ini kita mencoba membangun native smtp server dengan postfix yang disupport autentikasi dengan metode submission atau via port 587. Dan pada percobaan kali ini menggunakan CentOs 6, postfix biasanya sudah terinstall secara default. jika belum terinstall, bisa diinstall dengan perintah yum install postfix.

Konfigurasi Main.cf

relay_domains =
home_mailbox = Maildir/
mydomain = nws1.coabc.co.id
smtpd_use_tls = yes
smtpd_tls_key_file = /root/coabc.co.id/coabc.co.id.key
smtpd_tls_cert_file = /root/coabc.co.id/chained.crt
smtpd_tls_auth_only=yes
smtp_tls_security_level=may
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
smtpd_tls_protocols = !SSLv2, !SSLv3
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_protocols = !SSLv2, !SSLv3

smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
mailbox_size_limit = 256000000
myorigin = coabc.co.id
myhostname = coabc.co.id
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 10.15.0.6 1x.x.x 10.x.x.179
mydestination = newsletter.coabc.co.id, localhost.localdomain, localhost
recipient_delimiter = +
inet_interfaces = all

tambahkan user untuk account smtp:

adduser uuuuu

set password:

passwd pppp

ganti shell account diatas agar tidak bisa login ke console:

chsh -s /sbin/nologin uuuuu

tambahkan opsi submission di master.cf

submission inet n       -       n       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_reject_unlisted_sender=yes
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o broken_sasl_auth_clients=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

final konfig master.cf:

smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_reject_unlisted_sender=yes
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o broken_sasl_auth_clients=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
pickup    fifo  n       -       n       60      1       pickup
cleanup   unix  n       -       n       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       n       1000?   1       tlsmgr
rewrite   unix  -       -       n       -       -       trivial-rewrite
bounce    unix  -       -       n       -       0       bounce
defer     unix  -       -       n       -       0       bounce
trace     unix  -       -       n       -       0       bounce
verify    unix  -       -       n       -       1       verify
flush     unix  n       -       n       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       n       -       -       smtp
relay     unix  -       -       n       -       -       smtp
    -o smtp_fallback_relay=
showq     unix  n       -       n       -       -       showq
error     unix  -       -       n       -       -       error
retry     unix  -       -       n       -       -       error
discard   unix  -       -       n       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       n       -       -       lmtp
anvil     unix  -       -       n       -       1       anvil
scache    unix  -       -       n       -       1       scache

install cyrus sasl support plain tex dan md5t:

yum install cyrus-sasl-md5 cyrus-sasl-plain

konfig smtpd.conf

vim /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login

restart postfix dan saslauth daemon:

service saslauthd restart;service postfix restart

lalu test dengan php mailer (github.com/PHPMailer/PHPMailer)

<?php

//require_once('class.phpmailer.php');

require 'PHPMailerAutoload.php';

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = ''; // secure transfer enabled REQUIRED for GMail
$mail->Host = "nws1.coabc.co.id";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
//$mail->Username = "dian@infra.abc.co.id";
//$mail->Username = "oksoft@infra.abc.co.id";
$mail->Username = "userid";
//$mail->Password = "";
$mail->Password = "%pass";
$mail->SetFrom("noreply@coabc.co.id");
$mail->Sender="newsletter@coabc.co.id";
$mail->Subject = "Maju ED Lisensi";
$mail->Body = "Mohon Maju ED Lisensi, 23 Agustus 2016 ; dikarenakan belum melakukan pembayaran royalty Juli 2016\n\n
Terima Kasih\n
";
$mail->AddAddress("user@abc.co.id");
 if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }
?>

jalankan via php cli:

dgp@it-infra ~/Downloads/PHPMailer-master $ php nws1.apotekk24coid.php 
2016-08-23 03:07:06 CLIENT -> SERVER: EHLO it-infra
2016-08-23 03:07:06 CLIENT -> SERVER: STARTTLS
2016-08-23 03:07:06 CLIENT -> SERVER: EHLO it-infra
2016-08-23 03:07:06 CLIENT -> SERVER: AUTH LOGIN
2016-08-23 03:07:07 CLIENT -> SERVER: ZVFK
2016-08-23 03:07:07 CLIENT -> SERVER: OFI=
2016-08-23 03:07:07 CLIENT -> SERVER: MAIL FROM:<newsletter@coabc.co.id>
2016-08-23 03:07:07 CLIENT -> SERVER: RCPT TO:<user@abc.co.id>
2016-08-23 03:07:07 CLIENT -> SERVER: DATA
2016-08-23 03:07:07 CLIENT -> SERVER: Date: Tue, 23 Aug 2016 11:07:05 +0800
2016-08-23 03:07:07 CLIENT -> SERVER: To: user@abc.co.id
2016-08-23 03:07:07 CLIENT -> SERVER: From: noreply@coabc.co.id
2016-08-23 03:07:07 CLIENT -> SERVER: Subject: Maju ED Lisensi
2016-08-23 03:07:07 CLIENT -> SERVER: Message-ID: <7386bf71ad887e332566581c7aab9e5d@it-infra>
2016-08-23 03:07:07 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.13 (https://github.com/PHPMailer/PHPMailer)
2016-08-23 03:07:07 CLIENT -> SERVER: MIME-Version: 1.0
2016-08-23 03:07:07 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2016-08-23 03:07:07 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2016-08-23 03:07:07 CLIENT -> SERVER:
2016-08-23 03:07:07 CLIENT -> SERVER: Mohon Maju ED Lisensi, 23 Agustus 2016 ; dikarenakan belum melakukan pembayaran royalty Juli 2016
2016-08-23 03:07:07 CLIENT -> SERVER:
2016-08-23 03:07:07 CLIENT -> SERVER:
2016-08-23 03:07:07 CLIENT -> SERVER: Terima Kasih
2016-08-23 03:07:07 CLIENT -> SERVER:
2016-08-23 03:07:07 CLIENT -> SERVER:
2016-08-23 03:07:07 CLIENT -> SERVER: .
2016-08-23 03:07:07 CLIENT -> SERVER: QUIT
Message has been sent
dgp@it-infra ~/Downloads/PHPMailer-master $

done.