Search This Blog

Monday, November 8, 2010

configure postfix mail server.



This article explains how to setup a small mail server very fast on fedora system.

After following this tutorial, you will have : (1) MTA - postfix (2) SMTP authentication -

CYRUS SASL (3) IMAP and POP3 - Dovecot (4) Webmail - squirrelmail



(1) Firstly, we need to install packages needed. Login as root and install the packages using

YUM. Type the following command :

# yum install postfix dovecot cyrus-sasl cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl-lib

squirrelmail

Even if we have any of the packages already installed, it will just skip the installed ones.

Now, change the default mail transport agent, MTA. Type the following command and

choose postfix.

# system-switch-mail

Add postfix and dovecot and httpd (optionally if you choose to install the webmail) to

startup by

 # chkconfig --add postfix    and
 # chkconfig --add dovecot

and add these services to init levels 3 and 5 by

 # chkconfig --levels 35 postfix on
 # chkconfig --levels 35 dovecot on


(2) Configure postfix

The main configuration file for postfix lies in /etc/postfix/main.cf and change the following

values.

myhostname = mail.<your-real-internet-hostname-or-ipaddress>.com

This will be the address that will receive the mails.


mydomain = <real-domain-name>.com

This will be the domain your mails appear to be sent from.


init_interfaces = all

The address used for receiving the mail.


mydestination = $myhostname, $mydomainname, localhost, localhost.localdomain

Specify all hostnames pointing at your IP address but don't specify the domains here.


home_mailbox =  Maildir/

This is the path to save the mails to. The mailbox will store the mails to

/var/spool/mail/user or /var/mail/user. But Maildir/ will store mail in each user's home

directory (/home/user/Maildir).


Save the file and restart postfix.


# /etc/init.d/postfix restart


(3) Test your configurations.

Run the following command and check /root/Maildir/new for a message.

echo "Hello" | mail root


(4) Configure dovecot

Install dovecot and go to /etc/dovecot.conf file and change the following line :

protocols = imap pop3. Just remove the pound sign from the beginning of the line.

Restart dovecot.

Test :  # echo "Hello" | mail <username>


(5) Start Apache for webmail and dovecot.

# /etc/init.d/httpd restart
# /etc/init.d/dovecot restart


Test : Open your browser and go to  http://<your-hostname>.com/webmail and log in with

your user other than root.After logging in, you will have a new mail in  your mailbox.


(6) Enable SMTP authentication.

Edit the /etc/postfix/main.cf file and add this lines at the botton of the file.

smtpd_sasl_auth_enable = yes

smtpd_sasl_security_options = noanonymous

smtpd_sasl_local_domain = $myhostname

broken_sasl_auth_clients = yes

smtpd_recepient_restrictions = permit_sasl_auththenticated, check_relay_domains

Now, start saslauthd daemon and restart postfix.

# /etc/init.d/saslauthd restart
# /etc/init.d/postfix restart


(7) Open your email client (thunderbird,et cetera) and set your account as follows:

Incoming

Name : Your name
Email address : <non-root-user>@<your-real-internet-hostname>.com
Account password :
Server type = POP
Incoming server = mail.<your-domain>.com


Outgoing

Description : Something
Server Address : mail.<your-domain>.com
Port : 25
Check "My SMTP server requires authentication"
Username : <non-root-user>@<your-real-internet-hostname>.com
Password:
Choose "PLAIN" for authentication type.


If you want to receive root's mail to non-root user mailDir, edit the /etc/aliases file and

uncomment the root line to look like this.

root: <non-root-user>

# /etc/init.d/postfix restart