Setup Postfix/Dovecot MailServer for Centos/RHEL

Setup Basic POP3/IMAP Mail Server in Centos/RHEL

Setting up a mail server can be quite initimidating if you are linux beginner.
I am posting here my simple and most basic mail server experiment which i conducted
with my VPS server so that my documentation could be helpful for those who want
to setup a pop3 or imap mail server..

What you Need

– Linux Server with Centos 4/5 (VPS or Dedicated)
– Apache 2 with PHP4 or later
– Postfix (SMTP server or MTA)
– Dovecot ( IMAP/POP3 server)
– Squirrelmail (A free Webmail)

We will be setting up the email server for local users where they can use
webmail or outlook express to access their email. We will be setting up a simple
and most basic mail server for local users.

What you should know?

Before we proceed to setup a mail server, the following 3 are most important
for delivering email to destination. If you dont then most of the email origination
from your server will land up on spam folders in major free email providers
like hotmail or aol etc..

1. DNS Entry for your mail server with MX record
2. Setup an SPF record (see openspf.org
)
3. Setup Domain Name Keys
4 . Reverse IP for your Mail Server

The most important of it setting up reverse IP for your mail server. You have
to ask your hosting provider to setup a reverse IP for your mail server. Most
email providers will lookup reverse dns for the emails originating from your
server to distinguish from spam.

Install Postfix (SMTP Server/MTA)

Postfix is fast and popular SMTP server and widely used. Its main job is to
relay mail locally or to intended destination outside the network. Some of the
most popular SMTP servers are sendmail, postfix and qmail.

By default sendmail comes pre-installed with centos. We will need need to remove
it and install postfix.

yum remove sendmail
yum install postfix

The configuration file is located at /etc/postfix/main.cf.
Edit the file and make sure you change the following lines with your domain
name.
myhost= mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, $mydomain

You have to be careful about $mydestination is because it restrictions receiving
emails by the server pertaining to domains.

NOTE: Make sure you uncomment inet_interfaces = localhost
if you are enabling all option. I often made that dreadful mistake leaving both
uncommented!

Setting up SASL + TLS

We have to also setup SASL with our postfix to authenticate our users who want
to send email outside of the permitted network. We dont want our mail server
to be open relay and thereby restricting sending mail only to the local users.
Without SASL authentication postfix will give relay access denied error if you
attempt to send mail outside of the network.

yum install cyrus-sasl

To enable SASL authentication open /etc/postfix/main.cf and
add the following lines

smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

Install Dovecot (POP3/IMAP Server)

Dovecot is a very popular POP3/IMAP server. The main difference between POP3
and IMAP is while accessing the your email with outlook if you use POP3 the
mail is downloaded to your computer and deleted from the server. With IMAP the
mail is retained in the server. IF any problem occurs while downloading the
emails are lost with POP3. The configuration file is located at /etc/dovecot.conf

yum install dovecot

Open the dovecot config file /etc/dovecot.conf and make the
following changes. You may need to comment or uncomment certain lines

protocols = imap imaps pop3 pop3s
Look for the line auth default and make these changes. Be
careful with the lines as they are heavily commented out.

auth default {
mechanisms = plain login
passdb pam {
}
userdb passwd {
}
socket listen {
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
}

Install Squirrelmail

Squirrelmail is a free webbased email can be very handy for your users to login
while they are mobile.

yum install squirrelmail

To setup the squirrelmail under apache, open /etc/httpd/conf/httpd.conf

and insert the following lines

Alias /squirrelmail /usr/local/squirrelmail/www
<Directory /usr/local/squirrelmail/www>
Options Indexes
AllowOverride none
DirectoryIndex index.php
Order allow,deny
allow from all
</Directory>

The squirrelmail configuration utility is located in /usr/share/squirrelmail/config/conf.pl

Run the configuration utility and set the server settings to SMTP and change
your domain name to example.com

/usr/share/squirrelmail/config/conf.pl

Before you access squirrelmail or mail restart all the services


/etc/init.d/postfix start
/etc/init.d/dovecot start
/etc/init.d/saslauthd start
service httpd restart

To access squirrelmail point your browser to
http://www.domain.com/webmail
and the squirrelmail test page is located at http://domain.com/webmail/src/configtest.php

Before we login to squirrelmail, you will need to create users.

Create Local Users

Just create a localuser with adduser
adduser john
and update the password of john using

passwd john
Open squirrelmail and enter the username as john and the password

Using Outlook Express

To use outlook express create a mail account and try connecting to the server.
Email: john@domain.com
Incoming POP3 settings: mail.domain.com
Outgoing POP3 settings: mail.domain.com
UserName: john
Password: xxxx

NOTE: Before sending any outgoing email with outlook, make
sure you tick the My server requires authentication under server
settings.

FAQs

I am getting DNS error from my mail server? what entries should be
made in DNS zone file?

If you are using mail.domain.com then mail should have a CNAME record in your
dns zone file along with the MX record for the domain.
domain.com. IN MX 1 domain.com.
mail IN CNAME domain.com.

How do i test whether mail server is working or not?

The simplest way to check for your mail server working is enter your domain
in pingability.com
or dnsstuff.com and check for the errors.
You may also want to find if it is not open relay. Check your log file /var/log/maillog
for any errors as well.

Another way to test your mail server is using telnet. You will get output like
the one below.

> telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.simplegerman.com ESMTP Postfix
ehlo simplegerman.com
250-mail.simplegerman.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

NOTE: If you are using firewall make sure you dont block mail
server ports.

Similar Posts:

Tags:

Balakrishnan Prabhu

Mr. Balakrishnan Prabhu is the founder of Corpocrat magazine. He is also the founder of Best Citizenships (BC), assisting wealthy individuals with with global citizenship and residency programs in Europe. His other interests are Linux, Machine learning, Wordpress, etc. You can contact him here

  • Dmitry Nosov

    Greetings. I’m experiensing problem with postfix (SASL auth): everything works fine, but I cannot configure postfix so that it starts authenticating local users. This seem to be frustrating that somebody can specify MAIL TO: local user and is able to send message to another user inside the domain (mynetworks).

  • http://www.nobleflash.com jeff

    after use telnet to login, and enter the username and password, come oue a error:
    -ERR No INBOX for user.
    Connection closed by foreign host.

    what kind of problem on this?

  • http://www.dnlodge.com Marie Santos

    Can you please provide more details on this?

  • http://www.yeccos.com Vimalkumar

    Could you please tell me how to install Sieve Plugin to the Dovecot Email Server

  • gurpreet

    Hi, i followed the procedure mentioned by you and i’m getting this error… i guess somethin related to sasl thing…

    Jun 19 14:39:53 fedora postfix/smtpd[5606]: connect from ns1.kbgfedora.com[192.168.0.3]
    Jun 19 14:39:53 fedora postfix/smtpd[5606]: warning: SASL: Connect to private/auth failed: Permission denied
    Jun 19 14:39:53 fedora postfix/smtpd[5606]: fatal: no SASL authentication mechanisms
    Jun 19 14:39:54 fedora postfix/master[5406]: warning: process /usr/libexec/postfix/smtpd pid 5606 exit status 1
    Jun 19 14:39:54 fedora postfix/master[5406]: warning: /usr/libexec/postfix/smtpd: bad command startup — throttling

  • Rashid Iqbal

    Before configuring the SASL everything working fine
    but after configuring the SASL I tried to send the email from outlook express client get below error: although I am receiving emails internally

    The connection to the server has failed. Account: ‘mail.saudivalves.com’, Server: ‘mail.saudivalves.com’, Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 10061, Error Number: 0x800CCC0E

  • Lance

    Dude…I can’t tell you how much this article helped me setup a mail server for a much needed test environment. Thank you so much! I will mention one thing…the only additional step I needed was to change the ServerName property in the httpd.conf file to match my new domain name:

    ServerName http://www.example.com

    Thanks again for your efforts, they sure made my life easier!

  • Lance

    Ummm…without the http:// (the browser auto inserted those when I posted the comment). :)

  • Sheffy MK

    Thanks for the tutorial. It’s perfect.
    Is there any way to add quota to the mailbox?

  • Terry

    What a GREAT tutorial. simple, step by step! well done.

    BUT.. lol.. I am having trouble allowing people to connect in via Outlook, etc. I’ve tried all outlook variations of SSL, not SSL, uses authentication, not, etc. and it keeps timing out.
    There’s no firewall, can telnet in fine from shell, but not from remote..
    I can’t see any maillog errors either, and my VPS says no firewall is running..

    any ideas please? I’m sure it’s a config somewhere

  • sunny shah

    how to configure a postfix mail servver if we dont have a publik domain ??????????/

  • anon

    /etc/dovecot.conf => /etc/dovecot/dovecot.conf

  • http://vodent.com/?p=17976 apprendre les bases du forex

    Thank you, I’ve recently been searching for information
    about this topic for ages and yours is the best I have found
    out so far. But, what in regards to the conclusion?
    Are you sure about the source?