
POSTFIX MAIL SERVER IN LINUX
Postfix is a Mail Transfer Agent.Postfix is workhorse behind the mail receiving and sending.
A working mail server can be configured using Postfix (MTA) with the addition of some components like Dovecot (IMAP) and Roundcube (webmail).
Prerequisites :
CentOS 6: minimal installation(Only for testing)
Postfix: SMTP
Dovecot: IMAP, POP3
Roundcube: web-based IMAP client
Postfix admin: to easily manage Postfix
# To work properly, system needs to have selinux disabled.(Only for testing)
# To disable Selinux edit following file in /etc.
-> vi /etc/selinux/config
SELINUX=disabled
# Install Postfix in Linux System (Centos) From the console, install Postfix with yum command.
(With yum software in linux you can download and install software along with its dependencies software).
- yum install postfix
# Edit configuration file /etc/postfix/main.cf and set the parameters as follow:
myhostname = hostname.domain.com
mydomain = domain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8
home_mailbox = Maildir/
# Edit Postfix Mail.cf file in /etc/postfix/
-> vi /etc/postfix/main.cf
myhostname = hostname.domain.com
mydomain = domain.com
myorigin = $mydomain
inet_interfaces = all
# Change network ip range.
mynetworks = 192.168.1.0/24, 127.0.0.0/8
# Change mailbox default path for user.
home_mailbox = Maildir/
# Once all the parameters have been set, set application to start during system boot and start the service.
-> chkconfig postfix on
-> service postfix start
# Testing Postfix Server
To check if everything works as expected, type from terminal the following commands to send an email:
-> telnet localhost smtp
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 server.domain.com ESMTP Postfix
ehlo localhost
250-server.domain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: username@domain.com
250 2.1.0 Ok
rcpt to: username@domain.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 2C55A94
quit
221 2.0.0 Bye
Connection closed by foreign host.
# To check if the email has been received, have a look at the /home/username/Maildir/new directory.
-> cd /home/username/Maildir/new/
-> ll
-> cat xxxxx.xxxxx.servername.domain.com
The email was received by the system then the mail server is working properly.
Install Dovecot
While Postfix acts as Mail Transfer Agent (MTA) only, in order to retrieve emails using modern tools we need to enable IMAP/POP3 protocols. Dovecot is an application that acts as a secure IMAP and POP3 server.
# Use the yum command to install Dovecot
-> yum install dovecot
# Edit the configuration file /etc/dovecot/dovecot.conf to enable the needed protocols.
-> vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
# Then we need to specify the mail location by editing the file /etc/dovecot/conf.d/10-mail.conf.
-> vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
# Edit the file /etc/dovecot/conf.d/10-auth.conf and set the following parameters.
-> vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
#Last file to edit /etc/dovecot/conf.d/10-master.conf.
-> vi /etc/dovecot/conf.d/10-master.conf
unix_listener auth-userdb {
#mode = 0600
user = postfix
group = postfix
}
# Set Dovecot to start at system boot and start the service.
-> chkconfig dovecot on
-> service dovecot start
Testing Dovecot
To check if Dovecot is working, we test the program through the POP3 protocol.
-> telnet localhost pop3
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
+OK Dovecot ready.
user admin
+OK
pass password
+OK Logged in.
list
+OK 1 messages:
1 477
.
retr 1
+OK 477 octets
Return-Path: <username@domain.com>
X-Original-To: username@domain.com
Delivered-To: username@domain.com
Received: from localhost (localhost [IPv6:::1])
by server.domain.com (Postfix) with ESMTP id 2C55A94
for username@domain.com; Wed, 12 Jun 2013 12:22:00 +0200 (CEST)
Message-Id: <20130207113547.117113FF18@server.domain.com>
Date: Wed, 12 Jun 2013 12:22:00 +0200 (CEST)
From: username@domain.com
To: undisclosed-recipients:;
test postfix
.
quit
+OK Logging out.
Connection closed by foreign host.
# Now Install Roundcube
Roundcube is a browser-based an application-like user interface for mail server.
Before installing roundcube we need to install MySQL server and Apache in the Centos system.
# Install Mysql server and httpd server with the help of yum repository.
-> yum install mysql-server mysql-devel httpd
# Now both Apache and Mysql to start at system boot and enable services.
-> chkconfig httpd on
-> service httpd start
-> chkconfig mysqld on
-> service mysqld start
# Install EPEL repository for roundcube.
To install Roundcube with yum repository, we need to install the EPEL repository in the system.(You need working Internet connection).
-> wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
-> rpm -ivh epel-release-6-8.noarch.rpm
# Install Roundcube
-> yum install roundcubemail
Now we are going to Configure MySQL Server for Mail server.To define the database used by the Roundcube application, we need to access MySQL configuration.
# Login in mysql server
-> mysql -u root -p
#RUN THE FOLLOWING COMMANDS IN MYSQL SERVER
create database roundcube;
create user roundcube;
GRANT ALL PRIVILEGES ON roundcube.* TO roundcube@localhost IDENTIFIED BY ‘password’;
flush privileges;
use roundcube;
source /usr/share/doc/roundcubemail-0.8.6/SQL/mysql.initial.sql
quit
# Edit configuration file in /etc/roundcubemail/db.inc.php to set the parameters to access the mysql database.
-> vim /etc/roundcubemail/db.inc.php
(ADD OR UNCOMMENT BELOW LINE)
$rcmail_config[‘db_dsnw’] = ‘mysql://roundcube:password@localhost/roundcube’;
Edit the file in /etc/roundcubemail/main.inc.php to set the hostname chosen to perform the login.
-> vim /etc/roundcubemail/main.inc.php
(ADD OR UNCOMMENT BELOW LINE)
$rcmail_config[‘default_host’] = ‘localhost’;
To make the system accessible outside the server, edit the file in /etc/httpd/conf.d/roundcubemail.conf and set the correct parameter.
-> vim /etc/httpd/conf.d/roundcubemail.conf
(SEARCH AND CHANGE FOLLOWING PARAMETER)
Allow from all
Now star apache (httpd) service.
-> service httpd restart
Testing Roundcube User Interface mail Application go to your web browser and type below localhost address.
http://localhost/roundcubemail
Enter your credential then click Login.

THANK YOU..