authoryanuarakhid - 29 Jun 2021 • Baca 7 Menit

Tutorial Ubuntu 20.04 LTS : Cara Install dan Konfigurasi Mail Server Menggunakan Postfix dan Courier


Tutorial Ubuntu 20.04 LTS : Cara Install dan Konfigurasi Mail Server Menggunakan Postfix dan Courier

Pada postingan kali ini kita akan melakukan instalasi dan konfigurasi Mail Server Menggunakan Postfix dan Courier pada Sistem Operasi Ubuntu 20.04 LTS.

Prerequisite


Untuk membuat Mail Server hal utama yang diperlukan adalah sebuah DNS Server yang telah memiliki MX Record. Bagi yang belum punya DNS Server (Domain) bisa baca pada postingan sebelumnya.

Install


Sebelum melakukan instalasi terlebih dahulu lakukan update dan upgrade sistem.

$ sudo apt update && sudo apt upgrade

setelah itu lakukan instalasi paket postfix courier-imap courier-pop. Tunggu hingga proses selesai.

$ sudo apt install postfix courier-imap courier-pop

Pilih Yes. Lalu Enter.

Package configuration

 ┌───────────────────────┤ Configuring courier-base ├────────────────────────┐
 │                                                                           │
 │ Courier uses several configuration files in /etc/courier. Some of these   │
 │ files can be replaced by a subdirectory whose contents are concatenated   │
 │ and treated as a single, consolidated, configuration file.                │
 │                                                                           │
 │ The web-based administration provided by the courier-webadmin package     │
 │ relies on configuration directories instead of configuration files. If    │
 │ you agree, any directories needed for the web-based administration tool   │
 │ will be created unless there is already a plain file in place.            │
 │                                                                           │
 │ Create directories for web-based administration?                          │
 │                                                                           │
 │                    Yes                       No                           │
 │                                                                           │
 └───────────────────────────────────────────────────────────────────────────┘

Klik Enter.

Package configuration

 ┌───────────────────────┤ Configuring courier-base ├────────────────────────┐
 │                                                                           │
 │ SSL certificate required                                                  │
 │                                                                           │
 │ POP and IMAP over SSL requires a valid, signed, X.509 certificate.        │
 │ During the installation of courier-pop or courier-imap, a self-signed     │
 │ X.509 certificate will be generated if necessary.                         │
 │                                                                           │
 │ For production use, the X.509 certificate must be signed by a recognized  │
 │ certificate authority, in order for mail clients to accept the            │
 │ certificate. The default location for this certificate is                 │
 │ /etc/courier/pop3d.pem or /etc/courier/imapd.pem.                         │
 │                                                                           │
 │                                  Ok                                       │
 │                                                                           │
 └───────────────────────────────────────────────────────────────────────────┘

Klik Enter.

Package configuration
 ┌───────────────────────┤ Configuring courier-base ├───────────────────────┐
 │                                                                          │
 │ Courier MTA under courier user                                           │
 │                                                                          │
 │ The Courier MTA packaging has been extensively rewritten and major       │
 │ changes had been done to the default setup of Courier MTA.               │
 │                                                                          │
 │ The default user and group for Courier MTA has been changed to           │
 │ courier:courier.  The package tries hard to make all files belong to     │
 │ correct user:group and the permissions on those files are correct, but   │
 │ if you have a non-default setup, you will have to make sure that:        │
 │                                                                          │
 │  + All file owners and file in /etc/courier and /var/lib/courier         │
 │    are correctly set.                                                    │
 │  + MAILUSER and MAILGROUP settings in /etc/courier/esmtpd is set to      │
 │    correct user and group, both has to be set to `courier'.              │
 │                                                                          │
 │                                  Ok                                      │
 │                                                                          │
 └──────────────────────────────────────────────────────────────────────────┘

Klik Enter.

Package configuration
  ┌────────────────────────┤ Postfix Configuration ├────────────────────────┐
  │                                                                         │
  │ Please select the mail server configuration type that best meets your   │
  │ needs.                                                                  │ 
  │                                                                         │
  │  No configuration:                                                      │
  │   Should be chosen to leave the current configuration unchanged.        │
  │  Internet site:                                                         │
  │   Mail is sent and received directly using SMTP.                        │
  │  Internet with smarthost:                                               │
  │   Mail is received directly using SMTP or by running a utility such     │
  │   as fetchmail. Outgoing mail is sent using a smarthost.                │
  │  Satellite system:                                                      │
  │   All mail is sent to another machine, called a 'smarthost', for        │
  │ delivery.                                                               │
  │  Local only:                                                            │
  │   The only delivered mail is the mail for local users. There is no      │
  │                                                                         │
  │                                 Ok                                      │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘

Pilih Internet Site. Lalu klik Enter.

Package configuration

                   ┌──────┤ Postfix Configuration ├───────┐
                   │ General type of mail configuration:  │
                   │                                      │
                   │       No configuration               │
                   │       Internet Site                  │
                   │       Internet with smarthost        │
                   │       Satellite system               │
                   │       Local only                     │
                   │                                      │
                   │                                      │
                   │       Ok           Cancel            │
                   │                                      │
                   └──────────────────────────────────────┘

Masukan nama domain yang sudah dikonfigurasi MX Record nya. Lalu Enter.

Package configuration

 ┌─────────────────────────┤ Postfix Configuration ├─────────────────────────┐
 │ The "mail name" is the domain name used to "qualify" _ALL_ mail           │
 │ addresses without a domain name. This includes mail to and from root:     │
 │ please do not make your machine send out mail from root@example.org       │
 │ unless root@example.org has told you to.                                  │
 │                                                                           │
 │ This name will also be used by other programs. It should be the single,   │
 │ fully qualified domain name (FQDN).                                       │
 │                                                                           │
 │ Thus, if a mail address on the local host is foo@example.org, the         │
 │ correct value for this option would be example.org.                       │
 │                                                                           │
 │ System mail name:                                                         │
 │                                                                           │
 │  zonabiner.dev____________________________________________________________│
 │                                                                           │
 │                     Ok                        Cancel                      │
 │                                                                           │
 └───────────────────────────────────────────────────────────────────────────┘

Config


Buat direktori Maildir pada masing-masing home direktori user yang nantinya digunakan untuk menampung pesan email.

$ sudo maildirmake /etc/skel/Maildir

Perintah berikut digunakan untuk menambahkan direktori Maildir pada user yang sedang kita pakai saat ini.

$ maildirmake $HOME/Maildir

Konfigurasi Postfix pada file main.cf.

$ sudo nano /etc/postfix/main.cf

Pada mydestination tambahkan mx domain kalian. Pada mynetworks kalian bisa tambahkan blok network tertentu atau semuanya dengan wilcard all network 0.0.0.0/0. Dan pada akhir line tambahkan home_mailbox = Maildir/

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = zonabiner
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, zonabiner.dev, zonabiner, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 0.0.0.0/0
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/

Setelah konfigurasi selesai, Lakukan reload service postfix.

$ sudo systemctl reload postfix

Pengujian


Untuk melakukan pengujian kirim pesan email kita akan membuat 2 buah user baru contoh disini saya membuat user samsul dan ani.

$ sudo adduser samsul
$ sudo adduser ani

Add User in Ubuntu OS

Karena SMTP Running pada port 25 maka kita dapat melakukan akses menggunakan telnet atau nc untuk melakukan pengiriman pesan. Pada contoh berikut user samsul akan melakukan pengiriman email kepada user ani.

$ telnet zonabiner.dev 25
Trying 10.1.1.18...
Connected to zonabiner.dev.
Escape character is '^]'.
220 zonabiner ESMTP Postfix (Ubuntu)
mail from:samsul@zonabiner.dev
250 2.1.0 Ok
rcpt to:ani@zonabiner.dev
250 2.1.5 Ok
data
354 End data with CR LF.CR LF
ini email untuk mu ani
.
250 2.0.0 Ok: queued as 2A87D454BA
quit
221 2.0.0 Bye
Connection closed by foreign host.

Berikut demo melakukan pengiriman email menggunakan telnet.

Send Email using SMTP protocol and telnet

Sedangkan untuk melakukan pembacaan email kita akan menggunakan protokol pop3 yaitu yang running pada port 110.

$ telnet zonabiner.dev 110
Trying 10.1.1.18...
Connected to zonabiner.dev.
Escape character is '^]'.
+OK Hello there.
user ani
+OK Password required.
pass password
+OK logged in.
stat
+OK 1 426
retr 1
+OK 426 octets follow.
Return-Path: samsul@zonabiner.dev
X-Original-To: ani@zonabiner.dev
Delivered-To: ani@zonabiner.dev
Received: from zonabiner.dev (zonabiner.dev [10.1.1.18])
        by zonabiner (Postfix) with SMTP id 2A87D454BA
        for ani@zonabiner.dev; Tue, 29 Jun 2021 10:17:57 +0000 (UTC)
Message-Id: 20210629101806.2A87D454BA@zonabiner
Date: Tue, 29 Jun 2021 10:17:57 +0000 (UTC)
From: samsul@zonabiner.dev

ini email untuk mu ani
.
quit
+OK Bye-bye.
Connection closed by foreign host.

Berikut demo melakukan pembacaan email menggunakan telnet.

Read email using POP3 Protocol and Telnet

Sampai disini kita telah berhasil melakukan instalasi dan konfigurasi Mail Server menggunakan Postfix dan Courier.

Happy Config!! 😉

Tentang Penulis‎ ‏‏

author

Akhid Yanuar A.F

Linux System Administration | Computer Network | Operating System | Cloud Computing | IT Security | Linux Enthusiast 🐧

Find Me