Monday, December 26, 2011

Mail Server Configuration (Postfix+Dovecot+Squirrelmail)

Postfix: In computing, Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail. It is intended as a fast, easier-to-administer, and secure alternative to the widely-used Sendmail MTA.and first released in December 1998, Postfix continues as of 2011 to be actively developed by its creator and other contributors. The software is also known by its former names VMailer and IBM Secure Mailer.

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.

At first we check postfix 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-8.13.8-2.el5
[root@ns1 ~]# /etc/init.d/sendmail stop
[root@ns1 ~]# alternatives --set mta /usr/sbin/sendmail.postfix
Postfix configuration:
[root@ns1 ~]# yum install postfix* -y
[root@ns1 ~]# echo " " > /etc/postfix/main.cf
[root@ns1 ~]# vim /etc/postfix/main.cf

myhostname = mail.gix.com
mydomain = gix.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 172.22.0.0/16, 122.248.0.0/20, 202.84.64.0/24, 122.248.9.0/24, 203.
188.255.144/29, 192.168.50.0/24, 127.0.0.0/8
relay_domains =
home_mailbox = Maildir/
Here we restart postfix service :
[root@ns1 ~]# chkconfig postfix on
[root@ns1 ~]# /etc/init.d/postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]Here we user add for our mail server :

[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.
Here we can check users mail box :
[root@ns1 ~]# cd /var/spool/mail/
[root@ns1 mail]# ls
krahman rajan root rpc
Now try to login to the postfix server using telnet :
[root@ns1 ~]# telnet mail.gix.com 25
mail.gix.com/25: Name or service not known
[root@ns1 home]# telnet 192.168.50.18 25 Trying 192.168.50.18...
Connected to ns1.gix.com (192.168.50.18).
Escape character is '^]'.
220 mail.gix.com ESMTP Postfix

mail from:krahman@gix.com
250 2.1.0 Ok
rcpt to:rajan@gix.com
250 2.1.5 Ok
data354 End data with <CR><LF>.<CR><LF>

testmail.
250 2.0.0 Ok: queued as CD3408A882

subject:test1221 2.7.0 Error: I can break rules, too. Goodbye.
Connection closed by foreign host.

Dovecot configuration:

[root@ns1 home]# vim /etc/dovecot.conf
protocols = imap imaps pop3 pop3s
[root@ns1 home]# chkconfig dovecot on
[root@ns1 home]# /etc/init.d/dovecot restart
Stopping Dovecot Imap: [ OK ]
Starting Dovecot Imap: [ OK ]

[root@ns1 home]# yum install httpd* -y
[root@ns1 home]# chkconfig httpd on
[root@ns1 home]# /etc/init.d/httpd restart

[root@ns1 home]# yum install squirrelmail* -y
Squirrelmail default aliacing:
[root@localhost etc]# vim /etc/httpd/conf.d/squirrelmail.conf
Alias /webmail /usr/share/squirrelmail

In browser “ http://192.168.50.19/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.
alternative way
[root@localhost Server]#yum install postfix*
[root@localhost Server]#vim /etc/postfix/main.cf
just see 107 no: line here
[root@localhost Server]#postconf -e inet_interfaces=all
[root@localhost Server]#alternatives - - set mta /usr/sbin/sendmail.postfix
[root@localhost Server]#postconf -e "mynetworks_style=subnet"
[root@localhost Server]#postconf -e mynetworks_style=host"
[root@localhost Server]#postconf -e mynetworks=192.168.0.254, 127/8"
[root@localhost Server]#service postfix restart
[root@localhost Server]#service sendmail stop (if you face postfix fail)
[root@localhost Server]#useradd sales
[root@localhost Server]#vim /etc/aliases
sales: u1,u2,u3
[root@localhost Server]#newaliases
[root@localhost Server]#vim /etc/postfix/main.cf
RELAY
OK
DENY
[root@localhost Server]#postconf -e smtp_recipient_restrictions=check