Total Pageviews

Wednesday, February 29, 2012

Configure Centos(5.5) as Mail server

1)Configure host name lookup.
---------------
192.168.0.4 mail.yourdomain mail
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
---------------

2)Install system-switch-mail
---------------
yum install system-switch-mail
---------------
and configure MTA as postfix

3)Install and setup Postfix SMTP server.

-----------------
yum install postfix*
Edit '/etc/postfix/main.cf' and enter they following details.

inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/

After doing this, restart postfix

/etc/init.d/postfix restart

/sbin/chkconfig postfix on

4)Install and setup Dovecot POP3 and IMAP server.
yum install dovecot*

Edit /etc/dovecot.conf' and enter the following entries.

protocols = pop3 pop3s imap imaps
mail_location = maildir:~/Maildir/
pop3_uidl_format = %08Xu%08Xv
imap_client_workarounds = delay-newmail outlook-idle netscape-eoh
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh


After doing this, restart dovecot

/etc/init.d/dovecot restart

/sbin/chkconfig dovecot on

5)Install and setup SquirrelMail WebMail.

yum install squirrelmail*

From a Terminal window, type in /usr/share/squirrelmail/config/conf.pl and press Enter. This will launch the SquirrelMail Configuration utility.

Type in D and press Enter to select the Set pre-defined settings for specific IMAP servers menu. Type in dovecot and press Enter.

6) Relay Mails via gmail.

Installed postfix and removed sendmail:

# yum install postfix
# yum remove sendmail

Install openssl and openssl-perl are installed so we can generate certificates and create SSL connections to GMail

# yum install openssl openssl-perl

Create a Certificate Authority (if you don’t already have one):

# cd /etc/pki/tls/misc
# ./CA.pl -newca

You will be prompted for the file name (just hit Enter). Then you will be asked for a PEM pass phrase, which you need to remember. You can fill out the Country Name, State or Province Name, Locality Name, Organization Name, and Organizational Unit Name to your liking (or take the defaults). You need to remember the Organization Name (if you changed it) as it must match one in a key we create later. For the Common Name, fill in “CA” (without quotes). Take defaults for everything else and when prompted to enter the pass phrase you need to enter the same one you did above.

Create a client key that is sent to GMail to start the SSL encryption:

# cd /etc/pki/tls
# mkdir gmail_relay
# cd gmail_relay
# openssl genrsa -out server.key 1024
# openssl req -new -key server.key -out server.csr
# openssl ca -out server.pem -infiles server.csr

Add the following to the bottom of the file /etc/postfix/main.cf

#### GMail SSL SMTP Relay
relayhost = [smtp.gmail.com]:587

#auth
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

#tls
smtp_use_tls = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_note_starttls_offer = yes
tls_random_source = dev:/dev/urandom
smtp_tls_scert_verifydepth = 5
smtp_tls_key_file=/etc/pki/tls/gmail_relay/server.key
smtp_tls_cert_file=/etc/pki/tls/gmail_relay/server.pem
smtpd_tls_ask_ccert = yes
smtpd_tls_req_ccert =no
smtp_tls_enforce_peername = no

Create /etc/postfix/sasl_passwd file with your GMail login credentials that looks like below:

gmail-smtp.l.google.com user@gmail.com:password
smtp.gmail.com user@gmail.com:password

Create /etc/postfix/sasl_passwd.db file using the following command.
postmap hash:/etc/postfix/sasl_passwd

/etc/init.d/postfix restart

7) Fetch mails from gmail using fetchmail.

# vi /home/user/.fetchmailrc

Put a cron to download mails every minute.
#crontab -e
*/1 * * * * user fetchmail -k &> /dev/null

8) Login to webmail and check mails :)

No comments:

Post a Comment