MAIL Labour

Environment: Debian7 linux

Target: Setup mail server for:

  1. Sending mails between email users of class computers (using name resolution)
  2. Receiving emails by applications in different locations (mail client programms in win10, virtual machines and mobile phones)

Classroom A210, net name server for that labour dns server know it)
NB! If you will use it in another network, change IP, GW and mask.


MTA - Mail Transfer Agent
SMTP - Simple Mail Transfer Protocol
POP3 - Post Office Protovol v.3
IMAP - Internet Message Access Protocol
MAPI - Messaging Application Programming Interface

Linux programms for working with e-mail:

Sending email SMTP: Sendmail, Postfix, Exim, Qmail :PS!! One of them usualy already installed
Programms to get email by POP3, IMAP, MAPI: dovecot, prayer, ipopd, horde, cyrus, courier
Wemail: squirrelmail, sqwebmail, horde
Groupware server: kolabd Mail Kliendid: Thunderbird, Evolution, xmail, mutt, balsa
Antispam: spamassassin(spamd), razor, pyzor, greylistd
Antivirus: clamav

Labour Task:

We implement labour in one C-class segment(inside one classroom).
NB! In VirtualBox virtual machine set network insterface in bridge mode..
You mailserver name must be "". For example ""
DNS server of that domain or teachers classroom server(then all linux must use teachers server as name resolver).
You need to:


% usual user command line
$ superuser command line
In blue we mark content of the file
In purple we mark output of the programm

Before you begin

Check that linux can connect to classroom net and internet.
If you got IP address from DHCP server try to fix that address to be permanent on server
You can read about from Võrguvahendid

IP aadress, netmask ja gateway

If IP address is wrong or unknown try to get it by dhcpclient command:
$ dhclient

You can find active network interfaces, IP and mask of you linux under superuser by command(example from teacher server):
$ ifconfig
or under usual user:
% /sbin/ifconfig

eth0 Link encap:Ethernet HWaddr 08:00:27:d4:15:ad
inet addr: Bcast: Mask:
inet6 addr: fe80::a00:27ff:fed4:15ad/64 Scope:Link
RX packets:54244 errors:0 dropped:0 overruns:0 frame:0
TX packets:18493 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63963640 (61.0 MiB) TX bytes:1419471 (1.3 MiB)

You can see default route of you linux under superuser by command(example from teacher server):
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface UG 0 0 0 eth0 U 0 0 0 eth
Selleks ava fail /etc/network/interfaces ja muuda aktiivse võrgukaardi parameetrid, eth0 või eth1

You can check host machine and virtual machine IP addresses, if network addresses are equal yiu can fix them IP data in linux.
You can find interface rules are in /etc/network/interfaces:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
  address Youserver_ip
  gateway Youclass_gw
  netmask Youclass_netmask

For example in teacher server:
$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static

Edit that file to change interface settings for you need

Check content of the file :
$ cat /etc/network/interfaces

And after restart networking service:
$ /etc/init.d/networking restart


You need to add to firewall rules to enable TCP connections from classroom computers to port 25, 110 ja 143
If you do not known how to do it, disable firewall or uninstall all firewalls.
You can check current firewall rules by:

$ iptables -L -n

discover Ubuntu Networking Configuration Using Command Line

Check that you packet receive internet:
% ping

Change you hostname and mailname:

$ echo "yousurename" >/etc/hostname
$ echo "" >/etc/mailname

Check you changes :

$ hostname
$ cat /etc/mailname


Check DNS setting in /etc/resolv.conf

$ cat /etc/resolv.conf

search maltsev.op

Usually you do not need to change it. But if teacher will ask to do it get DNS IP from teacher.

Check our classroom host name resolution in mail servers
$ dig

Check internet name resolutions
$ ping


Check/install software

Install needed packages:
% sudo apt-get install postfix mutt dovecot-imapd thunderbird

NB! during installation you will be asked for some configuration:

  1. when install postfix select "Internet Site"
  2. you host name must be

Check that 25,110,143 ports are used:

% netstat -antp

check name resolution of you mail server from school internal dns resolvers :
% dig

# or try to ask main server
% dig @ # otse nimelahendaja arvutilt

Check and change only that rows in postfix configuration:
$ nano /etc/postfix/
myhostname = sinuperenimi.maltsev.op
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = sinuperenimi.maltsev.op
masquerade_domains = sinuperenimi.maltsev.op
mydestination = sinuperenimi.maltsev.op, B307, localhost.localdomain, localhost
relayhost =
mynetworks = 172.XXX.YYY.0/24 [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

Where 172.XXX.YYY.0/24 is classroom network address. That option enable postfix to receive and relay emails from that network.

Restart postfix:
$ service postfix restart

Check that 25 port on host are binded to postfix (master)

$ netstat -antp | grep :25
tcp 0 0* LISTEN 8746/master
tcp6 0 0 :::25 :::* LISTEN 8746/master

You can check sending and receiving protsess in log file /var/log/mail.log by command:
$ tail -f /var/log/mail.log

or using midnight commander viewer.

Check sending mail

Before sending e-mail please check :
1. postfix installed, configured and working in you mail server.
2. can you send mails from local user to local user in terminal.
3. are the mail destination host name is resolving to IP address
4. are the mail destination host is pinged and port 25 is open on destination host.

For sending mail please use mail client mutt, send mail under user it or some new user with tou name:
Teacher email is

it@mail:~$ mutt -x
You Surname
(End message with a . on a line itself)


Check email on destination server in folder /var/mail/ user can see content of the file with received messages.

PS! If you can not see sended email check log file /var/log/mail.log(or same kind of log) on both servers.


Geting mail by POP3 või IMAP protocol.

Install dovecot :

% sudo apt-get install dovecot-imapd dovecot-pop3d

NB! Check version of dovecot, configuration sre different !!


In /etc/dovecot/dovecot.conf need to uncomment or change next rows:

listen = *, ::
login_trusted_networks =

In /etc/dovecot/conf.d/10-mail.conf if row below is absent try to create one: NB! Uncomment other that kind of rows.

mail_location = mbox:~/mail:INBOX=/var/mail/%u

Edit authentication in config fail /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no

auth_mechanisms = plain login



In /etc/dovecot/dovecot.confneed to uncomment or change next rows:

protocols = pop3 pop3s imap imaps
ssl_disable = no
disable_plaintext_auth = no

auth default {
        mechanisms = plain login


and restart service

% service dovecot restart


% /etc/init.d/dovecot restart

Checkout that ports 110, 143, 993, 995 are used and binded to dovecot

% netstat -antp

Check from neighbour server that neede ports are open.

% nmap -P0 sinu_linuxi_IP

Install and run Mozilla Mail or Outlook under Windows host.
Create new user on linux with you name like peeter.
Create new aaccount for you server and set next options to connect to youn mail server.

Your name: Yourname Yousurname
E-Mail address: or some other user
Account Type: IMAP
Incoming mailserver (IMAP): name of you mail server(or IP address)
Outgoing mail server (SMTP): name of you mail server(or IP address)
User Name: peeter or other created user
Password: user_password