Email Server in details


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)

What you should know?
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

Install Postfix (SMTP Server/MTA)

#yum remove sendmail
#yum install postfix

#vi /etc/postfix/main.cf
myhost= mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, $mydomain

NOTE: Make sure you uncomment inet_interfaces = localhost

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.

#vi /etc/postfix/main.cf

add the following lines

smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destina tion
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

#vi /etc/dovecot.conf

#yum install dovecot
#vi /etc/dovecot.conf
protocols = imap imaps pop3 pop3s
Look for the line auth default and make these changes
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

#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

Create Local Users
#adduser john
#passwd john

Using Outlook Express
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.


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

No comments: