Linux | Cloud | DevOps | Scripting

Breaking

Saturday, 30 April 2016

Mail Server

In this article I am going to Install Local Mail Server Using Postfix, Dovecot and Thunderbird on Linux (rhel6)

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail. It is an alternative to Sendmail.
·         Dovecot is an open-source IMAP and POP3 server for Linux/UNIX-like systems.
·         Mozilla Thunderbird is a free, open source, cross-platform email system.

OS: RedHat (rhel6)
IP Address: 192.168.149.138
Hostname: example.com

PEREEQUISITES
Step1: Remove default MTA sendmail first if it’s already installed.
# yum remove sendmail –y
Step2. Add hostname entries in /etc/hosts file:
192.168.149.138         example.com   server
Step3. Disable SE-Linux
# vim /etc/selinux/config
SELINUX=disabled
(In case if we want to keep SE-Linux on, enter the following command in terminal)
# togglesebool httpd_can_network_connect
Step4: Allow the Apache default port 80 through your firewall/router:
# vi /etc/sysconfig/iptables
...
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
...

INSTALL POSTFIX:
Step1: Install postfix package
# yum install postfix –y
Step2: Edit /etc/postfix/main.cf file
# cp  /etc/postfix/main.cf  /etc/postfix/main.cf.bkp
# vi  /etc/postfix/main.cf
find and edit the following lines:
<< Line no 75 - Uncomment and set your mail server FQDN >>
myhostname = example.com
<< Line 83 - Uncomment and Set domain name >>
mydomain = example.com
<< Line 99 - Uncomment >>
myorigin = $mydomain
<< Line 116 - Set ipv4 >>
inet_interfaces = all
<< Line 119 - Change to all >>
inet_protocols = all
<< Line 164 - Comment >>
#mydestination = $myhostname, localhost.$mydomain, localhost,
<< Line 165 - Uncomment >>
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
<< Line 264 - Uncomment and add IP range >>
mynetworks = 192.168.1.0/24, 127.0.0.0/8
<< Line 419 - Uncomment >>
home_mailbox = Maildir/
Step3: Restart Postfix service now
# service postfix restart
# chkconfig postfix on

TESTING POSTFIX
Step1: Create a user named “dr”
# useradd dr
# passwd dr
Step2: Now access the server via telnet
# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.unixmen.local ESMTP Postfix
ehlo localhost     << type this command >>
250-server.unixmen.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<dr>     << Type this - mail sender address >>250 2.1.0 Ok
rcpt to:<dr>     << Type this - mail receiver address >>250 2.1.5 Ok
data     << Type this to input email message >>354 End data with <CR><LF>.<CR><LF>
This is my first mail server     << Enter the boddy of the email >>
<< To complete message, press enter and type dot (.) and again press enter >>
250 2.0.0 Ok: queued as B822221522
quit     << type this to quit from mail >>221 2.0.0 Bye
Connection closed by foreign host.
Step3: Navigate to the user “dr”
# ls /home/dr/Maildir/new/
1461667555.V802I45142M850831.example.com
A new mail is received to the user “dr“. To read the mail, enter the following command:
# cat /home/dr/Maildir/new/1461667555.V802I45142M850831.example.com
Return-Path: <dr@example.com>
X-Original-To: dr
Delivered-To: dr@example.com
Received: from localhost (localhost.localdomain [127.0.0.1])
    by example.com (Postfix) with ESMTP id 6AA4D27140
    for <dr>; Tue, 26 Apr 2016 16:15:31 +0530 (IST)
Message-Id: 20160426104541. 6AA4D27140@example.com
Date: Mon, 26 Apr 2016 16:15:31 +0530 (IST)
From: dr@example.com
To: undisclosed-recipients:;
This is my first mail server

INSTALL DOVECOT
Step1: Install Dovecot
# yum install dovecot –y
Step2: Configure Dovecot services in the Configuration File /etc/dovecot/dovecot.conf 
# vim /etc/dovecot/dovecot.conf
Uncomment the following line:
<< Line 25 - umcomment >>
protocols = imap pop3 lmtp
Step3: To set the location for your mail, use the Configuration File at /etc/dovecot/conf.d/10-mail.conf 
# vi /etc/dovecot/conf.d/10-mail.conf
Make the changes as shown below:
## Line 24 - uncomment ##
mail_location = maildir:~/Maildir
Step4: Configure the Authentication Process file /etc/dovecot/conf.d/10-auth.conf# vi /etc/dovecot/conf.d/10-auth.conf
And make the changes as shown below:
## line 9 - uncomment##
disable_plaintext_auth = yes
## Line 97 - Add a letter "login" ##
auth_mechanisms = plain login
Step5: Now change the Configuration File to configure Linux socket for postfix, by using the file /etc/dovecot/conf.d/10-master.conf,
# vi /etc/dovecot/conf.d/10-master.conf
Make changes as shown below:
## Line 79, 80 - Uncomment and add "postfix"
#mode = 0600
   user = postfix
   group = postfix
Step6: Restart Dovecot service
# service dovecot restart
# chkconfig dovecot on

TESTING DOVECOT
Step1: Enter the following command in Terminal:
# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user dr     << log in as user dr >>+OK
pass redhat     << input user password >>+OK Logged in.
retr 1+OK 425 octets
Return-Path: <dr@example.com>
X-Original-To: dr
Delivered-To: dr@example.com
Received: from localhost (localhost [127.0.0.1])
    by example.com (Postfix) with ESMTP id 0738427134
    for <dr>; Tue, 26 Apr 2016 13:11:43 +0530 (IST)
Message-Id: <
20160426074159.0738427134@example.com>
Date: Mon, 20 Jan 2014 16:23:54 +0530 (IST)
From: 
dr@example.com
To: undisclosed-recipients:;
This is my first mail server
quit
+OK Logging out.
Connection closed by foreign host.

INSTALLING MOZILLA THUNDERBIRD
Step1: Download Mozilla Thunderbird from link:
https://www.mozilla.org/en-US/thunderbird/
By Default it will install in /root/Downloads
Step2: Open a Terminal and Extract the contents of the downloaded file.
# cd /root/Downloads
# tar xjf thunderbird-*.tar.bz2
Step3: To start Thunderbird, run the thunderbird script in the thunderbird folder.
~/thunderbird/thunderbird
Step4: Run Thunderbird and go to
Edit > Account Settings > Account Actions > Add Mail Account >
Your Name: Divakar Rastogi
Email Address: dr@example.com
Password: ******
Click on Continue
If we want to use this account like IMAP, do not do anything, it will create automatically.
But if we want to use it as POP Account, click on Manual Config and do the following:
Incoming:
Incoming: POP3
Server Hostname: localhost
Port: 110
SSL: None
Authentication: Normal Password
Outgoing:
SMTP
Server Hostname: example.com:25(default)
Username:
Incoming: Divakar Rastogi
Outgoing: Divakar Rastogi
Done
[*] I understand the risk.


OK

1 comment:

Pages