Breaking

How to setup mail server using Postfix, Dovecot and SquirrelMail in CentOS/RHEL



In this tutorial, we explains How to setup mail server using Postfix, Dovecot and SquirrelMail in CentOS/RHEL

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail.

Dovecot is an open-source IMAP and POP3 server for Linux/UNIX-like systems.

SquirrelMail is a project that provides both a web-based email client and a proxy server for the IMAP protocol.



Prerequestics:


Step 1. Set your server hostname

To set your server hostname, edit /etc/sysconfig/network file

                 [root@mail ~]#  vim /etc/sysconfig/network




Step 2. Assign ststic IP and assign host entry in /etc/hosts 

                [root@mail ~]#  vim /etc/hosts




Step 3. Restart Network Service

             [root@mail ~]# /etc/init.d/network restart




Step 4. Reboot your system

Step 5. Check your hoatname by following command

               [root@mail ~]# hostname




Step 6. Disable your firewall and selinux

               [root@mail ~] # service iptables stop
               [root@mail ~] # service ip6tables stop
               [root@mail ~]# chkconfig iptables off
               [root@mail ~]# chkconfig ip6tables off

To disable selinux open /etc/selinux/config file and change SELINUX=disabled

               [root@mail ~]# vim /etc/selinux/config


Installation Steps


Install Postfix


Step 1. Before you install postfix, remove sendmail from your server. It is default Mail Transfer Agent in Redhat/Centos

               [root@mail ~]# yum remove sendmail


Step 2. Install Postfix

[root@mail ~]# yum install postfix




Step 3. Install SMTP AUTH Packages

[root@mail ~]#  yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain




Step 4. Create SSL Certificate

[root@mail ~]# mkdir  /etc/postfix/ssl
[root@mail ~]# cd  /etc/postfix/ssl
[root@mail ssl]# openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
[root@mail ssl]# chmod 600 smtpd.key
[root@mail ssl]# openssl req -new -key smtpd.key -out smtpd.csr




[root@mail ssl]# openssl x509 -req -days 365 -in smtpd.csr -signkey smtpd.key -out smtpd.crt




[root@mail ssl]# openssl rsa -in smtpd.key -out smtpd.key.unencrypted




[root@mail ssl]#  mv -f smtpd.key.unencrypted smtpd.key
[root@mail ssl]# openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 365




Step 5.  Open /etc/postfix/main.cf file

Find and comment below lines

inet_interfaces = localhost --->line no.116
mydestination = $myhostname, localhost.$mydomain, localhost ----->line no.164

Add these lines at the end of file

myhostname = mail.server.com
mydomain = server.com
myorigin = $mydomain
home_mailbox = mail/
mynetworks = 127.0.0.0/8
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = cyrus
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom




Step 6. Open /etc/postfix/master.cf and add lines after smtp.

smtps     inet  n       -       n       -       -       smtpd
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_reject_unlisted_sender=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o broken_sasl_auth_clients=yes




Step 7. Start postfix and saslauthd service

[root@mail ssl]# service postfix start
[root@mail ssl]# service saslauthd start

Step 8. Add service on startup

[root@mail ~]# chkconfig postfix on
[root@mail ~]# chkconfig saslauthd on




Step 9. check smtp connectivity.

[root@mail ~]# telnet localhost smtp and type 'ehlo localhost'


Install Dovecot


Step 1. Install and Configure dovecot.

[root@mail ~]# yum install dovecot

Step 2. After install open  /etc/dovecot/dovecot.conf and add the below lines at the end of file.

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

protocols = imap pop3
mail_location = maildir:~/mail
pop3_uidl_format = %08Xu%08Xv




Step 3. Start dovecot service

[root@mail ~]# service dovecot start

Step 4. Add dovecot service on startup

[root@mail ~]# chkconfig dovecot on




Step 5. Test pop3 connectivity

[root@mail ~]# telnet localhost 110 (pop3)




Step 6. Create a user and test

[root@mail ~]# useradd -m mortred -s /sbin/nologin
[root@mail ~]# useradd -m pugna -s /sbin/nologin
[root@mail ~]# passwd mortred
[root@mail ~]# passwd pugna


Install Squirrel mail


Follow the below steps to install and configure Squirrel Mail 

Step 1. Download Squirrel Mail

              # wget http://downloads.sourceforge.net/project/squirrelmail/stable/1.4.22/squirrelmail-webmail-1.4.22.zip

Step 2. Unzip Packages to /var/www/html/ directory

            # unzip squirrelmail-webmail-1.4.22.zip -d /var/www/html/

Step 3. Rename squirrelmail-webmail-1.4.22 to webmail 

            # mv /var/www/html/squirrelmail-webmail-1.4.22/ /var/www/html/webmail

Step 4. Change owner

            # chown -R apache: /var/www/html/webmail/

Step 5. # cd /var/www/html/webmail/config

Step 6. Rename config_default.php to config.php

            # cp -p config_default.php config.php

Step 7. start apache service

[root@mail ~]#  service httpd start

Step 8. Add apache service on startup

[root@mail ~]# chkconfig httpd on


Step 9. Run the below command to configure squirrelmail

              [root@mail ~]# perl /var/www/html/webmail/config/conf.pl




Step 10. Open config.php and edit as following

               [root@mail ~]# vim config.php


$domain = 'YOURDOMAIN.COM';
$data_dir = '/var/www/html/webmail/data/';
$attachment_dir = '/var/www/html/webmail/attach/';
$smtpServerAddress = 'localhost';
$imapServerAddress = 'localhost';



--------------------------------------------------------------------------------------------------------------

Note: Increase SquirrelMail maximum attachment size.


[root@mail ~]#vim /etc/php.ini

Search for upload_max_filesize.
Change 2M to something else, for example 5M.
If the upload_max_filesize is larger than post_max_size, you must increase post_max_size so that it's bigger than upload_max_size
If the value of post_max_size is larger than memory_limit, you must increase memory_limit so that it's larger than post_max_size.
Save your changes to the file.
Restart your web server.
If uploading the file is slow, you may have to increase the max_execution_time so that the script does not terminate before the entire file is uploaded.


Testing








No comments:

Powered by Blogger.