T-110.5102 Laboratory Works in Networking and Security (5-10 cr)

Lab A2: E-mail server


Description of the exercise

In this exercise you will learn how to setup an email server with filtering rules and spam detection. Take into account that from now on you'll have to do extensive self-research to be able to successfully complete the assignments.


1. Preparation

During this assignment you will need two hosts (lab1 and lab2). Add the IPv4 addresses and aliases on both computers to the /etc/hosts file. Stop any daemons that might be listening on the default SMTP port.


2. Installing software

On lab1, verify that the following packages are installed:

postfix, procmail, spamassassin, and mailx.

On lab2, install exim4.


3. Configuring and testing postfix

Edit postfix main configuration file (main.cf, postconf(5)) on lab1. You have to change, at least, the following fields:

  • myhostname (from /etc/hosts)
  • mydestination
  • mynetworks (localhost and virtual machines IP block)

Disable ETRN and VRFY commands. Remember to reload postfix service /etc/init.d/postfix).

Configure exim4 on lab2 to handle local emails and send all the rest to lab1. You might want to use standard debian package configuration tools.

Send a message from lab2 to <user>@lab1 using mail(1). Replace the <user> with your username. Read the message on lab1. See also email message headers. See incoming message information from /var/log/mail.log using tail(1).

3.1 Explain shortly the incoming mail log messages 2 p
3.2 Explain shortly the email headers. At what point is each header added? 2 p
3.3
What is purpose of the main.cf setting "mydestination"?
1 p
3.4 What is the idea behind the ETRN and VRFY verbs? 2 p 
3.5 Why it is really bad idea to set mynetworks broader than necessary (e.g. to 0.0.0.0/0)?
1 p

4. Configuring procmail and spamassassin

Edit (create if necessary) /etc/procmailrc (5) and add the following lines:

:0fw
| /usr/bin/spamassassin

In main.cf, you have to enable procmail with mailbox_command line

/usr/bin/procmail -a "$USER"

Remember to reload postfix configuration. You may need to start the SpamAssassin daemon after flipping the enabling bit in the configuration file.

Send an email message from lab2 to <user>@lab1. Read the message on lab1. See email headers. If you do not see spamassassin headers there is something wrong, go back to previous step and see /var/log/mail.log.

Use procmail to automatically filter spam messages to a different folder.

Add also a filter for your user to automatically save a copy of a message with header [T-110.5102] in the subject field to a different folder. Also forward a copy of the message with the same header to testuser1@lab1 (create user if necessary).

Note: Use .procmailrc file in user's home directory for user-specific rules.  

4.1
How you can automatically filter spam messages to different folder using procmail? Demonstrate by sending a message that gets flagged as spam.
2 p
4.2 Demonstrate the filter rules created for messages with [T-110.5102] in the subject field by sending a message from lab2 to <user>@lab1 using the header. 2 p 
4.3 Explain briefly the additional email headers (compared to step 3.2). 1 p

5. Final questions

5.1
What information is stored in MX records in the DNS system? 1 p
5.2
Explain briefly two ways to make redundant email servers using multiple servers and DNS.
Hint: Using multiple DNS servers is not the correct answer!
2 p

6. Finishing your work

When finishing your work, please remember to backup your related files from the lab computers to a safe place (e.g. your home directory in Niksula or the Computer Center). The course does not provide any back up service for the virtual machines.