Thursday, February 14, 2013

Setting Up Mail Server on CENT OS

1. Install packages

Three packages are required for this. Install them if you haven't done yet.
$yum install sendmail
$yum install sendmail-cf
$yum install dovecot

The role of sendmail is to receive emails destined to you and keep them in your mailbox on email server. Then, dovecot actually delivers those emails to your PC when you open Thunderbird or Microsoft Outlook. For outgoing email, Thunderbird first contacts sendmail, then sendmail relays the email to final destination for you.

2. Configure sendmail

You just need to change 2 lines in configuration file /etc/mail/sendmail.mc

Comment out this to allow receiving email from anywhere.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl


Add this line
FEATURE(`relay_hosts_only')dnl

Add your PC's full hostname in this file. Create one if this file doesn't exist.
/etc/mail/relay-domains.m4

After changing configuration file, run this command to activate it.

$/etc/mail/make
$service sendmail start

3. Configure dovecot

You just need to edit two files.

In /etc/dovecot/dovecot.conf, just edit these two lines
protocols = imap
listen = *, ::

In /etc/dovecot/dovecot.d/10-mail.conf, edit these 3 lines

mail_location = mbox:~/mail:INBOX=/var/mail/%u
mail_privileged_group = mail
mbox_write_locks = dotlock fcntl

Start dovecot service
$service dovecot start

4. (Optional) Reconfigure iptables only if you are already using iptables
Add these 2 lines into /etc/sysconfig/iptables to allow email to go through firewalls.

-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 993 -j ACCEPT

then, restart iptables by
$service iptables restart

DONE

No comments:

Post a Comment