Wednesday, February 8, 2012

Setting up email server on CentOS 6.2 within 5 minutes

If you have only 5 minutes,  you can still setup an email server on CentOS 6.2. Don't waste it :)

This email server supports SMTP(TCP port 25) and IMAPS(secure IMAP,TCP port 993). Now, you can specify this as an outgoing and incoming email server on email client such as Thunderbird on your PC.

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/

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

Add this line

Add your PC's full hostname in this file. Create one if this file doesn't exist.

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

$service sendmail start

3. Configure dovecot

You just need to edit two files.

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

In /etc/dovtcot/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


This is it. Of course, you can do more to enhance the security level of your email server. For example, you can make sendmail more secure by using SMTP over SSL. Feel free to suggest any idea about this article. Thanks.


  1. Thanks for posting this "right to the point" how-to. Besides a couple of type-o's it was very helpful.

  2. This is excellent. I have been trying to setting up sendmail to deliver email from centos. I have googled so many different places and sites without success. The steps here are so simple and most importantly, it works.

    Only a couple of typos need slight correction.
    1. change this /etc/mail/relay-domains to /etc/mail/relay-domains.m4
    2. change this /etc/dovecot/dovtcot.conf to /etc/dovecot/dovecot.conf
    3. change this /etc/dovtcot/dovecot.d/10-mail.conf to /etc/dovecot/conf.d/10-mail.conf

    One can then use the sendmail command line to test. For example -
    #sendmail -t
    subject:this is sendmail test
    this is message body.

  3. I am trying to setup sendmail on a CentOS server.
    I followed all instructions above.
    I can send mail to a local user from the command line.
    All email is forwarded to my gmail account and it gets there.

    If I send the same email from Outlook, I get no error message but
    the email is nowhere to be found. Any tips would be greatly appreciated.

  4. Thanks alot, it works, just consider the remarks make by Wang Yahping.