Linux Mail Server with Postfix and Dovecot 3

Getting Started

Log into SSH as the primary user and then switch user to root by typing "su -" (without the quotes).

To obtain further information on adding and removing users, type the following commands:
man useradd
man usermod
man userdel
These commands will bring up the Linux user help files.

Processes

A. Stopping and Turning off Sendmail

1. Execute the following command to stop sendmail:
[root@server ~]# service sendmail stop

2. Execute the following command to ensure that Sendmail does not start at boot:
[root@server ~]# chkconfig sendmail off

B. Installing Postfix and Dovecot

3. Use yum to install the necessary packages, it will resolve any necessary dependencies.
[root@server ~]# yum install postfix system-switch-mail dovecot

4. Switch the default SMTP server to Postfix:
[root@server ~]# system-switch-mail

5. Select postfix from the list and pick OK. Pick OK once you get the message saying “Your MTA configuration has successfully been updated”.

C. Update Your Firewall Rules (if necessary)

6. Add firewall rules to allow traffic for:
SMTP:
[root@server ~]# iptables -I INPUT -p tcp --dport 25 -j ACCEPT

POP3:
[root@server ~]# iptables -I INPUT -p tcp --dport 110 -j ACCEPT

IMAP:
[root@server ~]# iptables -I INPUT -p tcp --dport 993 -j ACCEPT

7. Save your iptables configuration:
[root@server ~]# service iptables save

D. Edit the Postfix Configuration file

The postfix configuration file is /etc/postfix/main.cf. Edit the file according to your server/domain following the following as a guide. example.com is shown for example purposes, substitute your domain as needed.

8. Look for the following lines and modify as needed:
myhostname = mail.example.com
mydomain = example.com

9. Comment out this line (using a # at the start)
inet_interfaces = localhost

10. Append to this line the right hand sides of your email addresses handled by the machine (example.com shown as example)
mydestination=$myhostname, localhost.$mydomain, example.com

11. Uncomment this line and add your networks (192.168.1.0/16 shown as example)
mynetworks=127.0.0.0/8,192.168.0.0/16

12. Save the file.

E. Start Postfix

The postfix must be started for SMTP to work. You should also set postfix to start at boot time.

13. Execute the following command to start postfix:
[root@server ~]# service postfix start

14. Execute the following command to ensure that postfix starts at boot time:
[root@server ~]# chkconfig postfix on

F. Troubleshooting

If you need to troubleshoot, the mail logs are located in /var/log/maillog.

15. You can monitor the mail logs by executing the following command:
[root@server ~]# tail /var/log/maillog

G. Testing

You should now be able to send mail using postfix. The quickest way to test it is using the command line mail command. Test it with an known valid email address you can check.

16. Execute the following command to test postfix and SMTP
[root@server ~]# mail someone@example.com

You will be prompted to enter a Subject, enter testing, press enter. Now enter the body of the email, when finished press CRTL+D. You will be prompted to enter a CC, leave it blank and press enter to send the mail message.

17. Check the email address you sent the message to. If you received the message then postfix is working.

H. Configure Dovecot

18. Change to the /usr/share/ssl/certs directory and perform the following commands:
[root@server ~]# cd /usr/share/ssl/certs
[root@server ~]# mv dovecot.pem dovecot.pem.dead
[root@server ~]# make dovecot.pem

19. Answer the questions it prompts you for, and then when it is done execute the following commands:
[root@server ~]# cp dovecot.pem ../private
[root@server ~]# vi ../private/dovecot.pem

20. Remove the "certificate" section leaving just the private block.
Now, change the permissions of these files.

21. Execute the following commands:
[root@server ~]# chmod 600 dovecot.pem
[root@server ~]# chmod 600 ../private/dovecot.pem

By default Dovecot will only handle IMAP, we will need to edit the Dovecot configuration file to add support for POP3. The dovecot configuration file is /etc/dovecot.conf. Edit the file according to your server/domain following the following as a guide.

22. Uncomment this line and add the POP3 protocols (pop3 and pop3s)
protocols = imap pop3 imaps pop3s

23. Save the file.

I. Start Dovecot

The dovecot service must be started for mail reception to work. You should also set dovecot to start at boot time.

24. Start the dovecot service by executing the following command:
[root@server ~]# service dovecot start

25. Ensure that dovecot starts at boot time by executing the following command:
[root@server ~]# chkconfig dovecot on

You should be up and running.

Add Feedback