Monday, December 26, 2011

Mail Server Configuration(Sendmail+Dovecot+Squirrelmail)

Sendmail: On the Internet, sendmail is the most popular UNIX-based implementation of the Simple Mail Transfer Protocol (SMTP) for transmitting e-mail.Sendmail is a general purpose internetwork email routing facility that supports many kinds of mail-transfer and -delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet.

Dovecot : is an open source IMAP and POP3 server for Linux/UNIX-like systems, written primarily with security in mind. Developed by Timo Sirainen, Dovecot was first released in July 2002. Dovecot primarily aims to be a lightweight, fast and easy to set up open source mailserver.

SquirrelMail :is an Open Source project that provides both a web-based email application and an IMAP proxy server.It is a standards-based webmail package written in PHP. It includes built-in pure PHP support for the IMAP and SMTP protocols, and all pages render in pure HTML 4.0 (with no JavaScript required) for maximum compatibility across browsers. It has very few requirements and is very easy to configure and install. SquirrelMail has all the functionality you would want from an email client, including strong MIME support, address books, and folder manipulation.
Configuration :
At first we check sendmail package is already installed or not. And also need to disable all other MTA if exist

[root@ns1 ~]# rpm -qa | grep postfix*
[root@ns1 ~]# rpm -qa | grep sendmail*

Sendmail Server Configuration:

[root@dns1 ~]# yum install sendmail* -y
[root@dns1 ~]# yum install m4* -y
[root@dns1 ~]# yum install dovecot* -y

[root@dns1 ~]# vim /etc/mail/sendmail.mc
Edit /etc/mail/sendmail.mc , search for DAEMON_OPTIONS and add comments :
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl Search for LOCAL_DOMAIN and add DNS name : LOCAL_DOMAIN(`tsdatabd.com')dnl
Mail relay approve or reject , in sendmail.mc we need to find for blacklist then UN -comment this line
FEATURE(`blacklist_recipients')dnl
[root@dns1 ~]# vim /etc/mail/access
Connect:192.168.50.0/24 RELAY
Connect:mail.tsbd.com RELAY
Connect:tsbd.com RELAY
[root@dns1 ~]#makemap hash /etc/mail/access.db < /etc/mail/access
One should modify sendmail macro configuration file: /etc/mail/sendmail.mc and then generate sendmail.cf with m4 macro processor: m4. /etc/mail/sendmail.mc ...
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Edit the file named “/etc/mail/local-host-names” and add the following ( machine ip address for
example my ip is 192.168.50.20)
[root@dns1 ~]# vim /etc/mail/local-host-names
192.168.50.19
mail.tsdatabd.com
tsdatabd.com
[root@dns1 ~]# vim /etc/aliases
support: rajan,saiful,krahman,probal,support,mominul
[root@dns1 ~]# newaliases
/etc/aliases: 76 aliases, longest 43 bytes, 798 bytes total

[root@dns1 ~]#chkconfig sendmail on
[root@dns1 ~]# /etc/init.d/sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@ns1 ~]# useradd -s /sbin/nologin krahman
[root@ns1 ~]# passwd krahman
Changing password for user krahman.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@ns1 ~]# useradd -s /sbin/nologin rajan
[root@ns1 ~]# passwd rajan
Changing password for user rajan.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

[root@dns1 ~]# telnet mail.tsbd.com 25
mail.tsbd.com/25: Name or service not known
[root@ns1 ~]# telnet 192.168.50.20 25
Trying 192.168.50.20...
Connected to ns1.tsbd.com (192.168.50.20).
Escape character is '^]'.
220 ns1.tsbd.com ESMTP Sendmail 8.13.8/8.13.8; Mon, 28 Nov 2011 20:12:59 +0600
mail from:krahman@tsbd.com
250 2.1.0 krahman@tsbd.com... Sender ok
rcpt to:rajan@tsbd.com
250 2.1.5 rajan@tsbd.com... Recipient ok
data
354 Enter mail, end with "." on a line by itself
subject:test mail
This is the test mail from krahman
hello rajan how r u ?
.
250 2.0.0 pASECxJb024741 Message accepted for delivery
quit
221 2.0.0 ns1.tsbd.com closing connection
Connection closed by foreign host.

[root@ns1 ~]# vim /etc/dovecot.conf

protocols = imap imaps pop3 pop3slogin_greeting = welcome to tsbd
[root@ns1 ~]# chkconfig dovecot on
[root@ns1 ~]# /etc/init.d/dovecot restart
Stopping Dovecot Imap: [FAILED]
Starting Dovecot Imap: [ OK ]
[root@ns1 ~]# telnet 192.168.50.20 110
Trying 192.168.50.20...
Connected to ns1.tsbd.com (192.168.50.20).
Escape character is '^]'.
+OK welcome to tsbd
user rajan
+OK
pass 123456
+OK Logged in.
list
+OK 3 messages:
1 484
2 436
3 504
.

retr 3
+OK 504 octets
Return-Path: <krahman@tsbd.com>
Received: from ns1.tsbd.com (ns1.tsbd.com [192.168.50.20])
by ns1.tsbd.com (8.13.8/8.13.8) with SMTP id pASECxJb024741
for rajan@tsbd.com; Mon, 28 Nov 2011 20:14:01 +0600
Date: Mon, 28 Nov 2011 20:12:59 +0600
From: krahman@tsbd.com
Message-Id: <201111281414.pASECxJb024741@ns1.tsbd.com>
X-Authentication-Warning: ns1.tsbd.com: ns1.tsbd.com [192.168.50.20] didn't use HELO protocol
subject: test mail

This is the test mail from krahman
hello rajan how r u ?
.
retr 2
+OK 436 octets
Return-Path: <krahman@tsbd.com>
Received: from ns1.tsbd.com (ns1.tsbd.com [192.168.50.20])
by ns1.tsbd.com (8.13.8/8.13.8) with SMTP id pASE8uw8024573
for rajan@tsbd.com; Mon, 28 Nov 2011 20:09:57 +0600
Date: Mon, 28 Nov 2011 20:08:56 +0600
From: krahman@tsbd.com
Message-Id: <201111281409.pASE8uw8024573@ns1.tsbd.com>
X-Authentication-Warning: ns1.tsbd.com: ns1.tsbd.com [192.168.50.20] didn't use HELO protocol

test mail
.
retr 1
+OK 484 octets
Return-Path: <krahman@tsbd.com>
Received: from ns1.tsbd.com (ns1.tsbd.com [192.168.50.20])
by ns1.tsbd.com (8.13.8/8.13.8) with SMTP id pASDl2F7023801
for rajan@tsbd.com; Mon, 28 Nov 2011 19:48:59 +0600
Date: Mon, 28 Nov 2011 19:47:02 +0600
From: krahman@tsbd.com
Message-Id: <201111281348.pASDl2F7023801@ns1.tsbd.com>
X-Authentication-Warning: ns1.tsbd.com: ns1.tsbd.com [192.168.50.20] didn't use HELO protocol

This is the test mail from krahman
hello rajan how r u ?
.
dele 2
+OK Marked to be deleted.
list
+OK 2 messages:
1 484
3 504

[root@ns1 ~]# yum install squirrelmail* -y
[root@ns1 ~]# yum install php* -y
[root@ns1 ~]# yum install httpd* -y
[root@ns1 ~]# chkconfig httpd on
[root@ns1 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@ns1 ~]# cd /usr/share/squirrelmail/config/
[root@ns1 config]# ls
config_default.php config_local.php config.php conf.pl index.php
[root@ns1 config]# ./conf.pl
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> 1SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : SquirrelMail
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://www.squirrelmail.org/
8. Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
X-Net Ltd
S
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : X-Net Ltd
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://www.squirrelmail.org/
8. Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
[root@ns1 ~]# cd /usr/share/squirrelmail/images/here pase the logo
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : X-Net Ltd
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://www.squirrelmail.org/
8. Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 2

Your organization's logo is an image that will be displayed at
different times throughout SquirrelMail.
Please be aware of the following:
- Relative URLs are relative to the config dir
to use the default logo, use ../images/sm_logo.png
- To specify a logo defined outside the SquirrelMail source tree
use the absolute URL the webserver would use to include the file
e.g. http://www.example.com/images/mylogo.gif or /images/mylogo.jpg

[../images/sm_logo.png]: ../images/xnet.jpg
S
Organization Preferences
1. Organization Name : X-Net Ltd
2. Organization Logo : ../images/xnet.jpg
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://www.squirrelmail.org/
8. Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit

General
-------
1. Domain : localhost
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit

Server Settings

General
-------
1. Domain : tsbd.com
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit

Squirrelmail default aliacing:

[root@localhost etc]# vim /etc/httpd/conf.d/squirrelmail.conf
Alias /webmail /usr/share/squirrelmail

In browser “ http://192.168.50.20/webmail


Here we provide host entry for our mail server : If we provide host record then we can use our mail server with domain name

[root@ns1 home]# vim /var/named/chroot/var/named/gix.fz IN NS ns1.gix.com.
IN NS ns2.gix.com.
IN A 192.168.50.18
ns1 IN A 192.168.50.18
ns2 IN A 192.168.50.21
mail IN A 192.168.50.18

[root@ns1 home]# vim /var/named/chroot/var/named/gix.rz

IN NS ns1.gix.com.
IN NS ns2.gix.com.
18 IN PTR ns1.gix.com.
21 IN PTR ns2.gix.com.
100 IN PTR mail.gix.com.

[root@ns1 home]# /etc/init.d/named restart
Stopping named: . [ OK ]
Starting named: [ OK ]
[root@ns1 home]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

In browser"http://mail.tsbd.com/webmail"





Here we provide MX record for our mail server : If we provide MX record then our mail server will route our mail to all other mail server in the world


[root@ns1 home]# vim /var/named/chroot/var/named/gix.fz


IN NS ns1.gix.com. IN MX 10 mail.gix.com.
IN NS ns2.gix.com.
IN A 192.168.50.18
ns1 IN A 192.168.50.18
ns2 IN A 192.168.50.21
mail IN A 192.168.50.18



[root@ns1 home]# vim /var/named/chroot/var/named/gix.rz

IN NS ns1.gix.com.
IN MX 10 mail.gix.com.
IN NS ns2.gix.com.
18 IN PTR ns1.gix.com.
21 IN PTR ns2.gix.com.
100 IN PTR mail.gix.com.


iptables for mail port 25 & 110


Then we edit /etc/sysconfig/iptables file, as we are using smtp then we just need to open 25 port
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 25 -j ACCEPT
Restart iptables


Then we do following to edit firewall as we are using pop3 then we just need to open 110 port
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 110 -j ACCEPT Restart iptables