Setup Basic POP3/IMAP Mail Server in Centos/RHEL
Setting up a mail server can be quite intimidating 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..
- 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.
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.
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.
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.
You have to be careful about $mydestination is because it restrictions receiving emails by the server pertaining to domains.
NOTE: Make sure you uncomment if you are enabling all option. I often made that dreadful mistake leaving both uncommented!
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.
To enable SASL authentication open and add the following lines
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
Open the dovecot config file /etc/dovecot.conf and make the following changes. You may need to comment or uncomment certain lines
Look for the line auth default and make these changes. Be careful with the lines as they are heavily commented out.
Squirrelmail is a free webbased email can be very handy for your users to login while they are mobile.
To setup the squirrelmail under apache, open and insert the following lines
The squirrelmail configuration utility is located in
Run the configuration utility and set the server settings to SMTP and change your domain name to example.com
Before you access squirrelmail or mail restart all the services
To access squirrelmail point your browser to and the squirrelmail test page is located at
Before we login to squirrelmail, you will need to create users.
Create Local Users
Just create a localuser with adduser
and update the password of john using
Open squirrelmail and enter the username and the password
To use outlook express create a mail account and try connecting to the server.
Before sending any outgoing email with outlook, make sure you tick the under server settings.
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.
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 for any errors as well.
Another way to test your mail server is using telnet. You will get output like the one below.