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 172.18.11.0/24 name server for that labour 193.40.160.1(school dns server know it)
NB! If you will use it in another network, change IP, GW and mask.

Termins:

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 "yousurname.yougroup.tpt.edu.ee". For example "tortikoff.kit16v.tpt.edu.ee"
DNS server of that domain 193.40.160.1 or teachers classroom server(then all linux must use teachers server as name resolver).
You need to:

Meanings

% 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:172.18.11.27 Bcast:172.18.11.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fed4:15ad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
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
0.0.0.0 172.18.11.254 0.0.0.0 UG 0 0 0 eth0
172.18.11.0 0.0.0.0 255.255.255.0 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
  address 172.18.11.27
  gateway 172.18.11.254
  netmask 255.255.255.0


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

Firewall

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 8.8.8.8

Change you hostname and mailname:

$ echo "yousurename" >/etc/hostname
$ echo "yousurename.kit16v.tpt.edu.ee" >/etc/mailname

Check you changes :

$ hostname
veeremaa
$ cat /etc/mailname
veeremaa.kit16v.tpt.edu.ee

DNS

Check DNS setting in /etc/resolv.conf

$ cat /etc/resolv.conf
nameserver 192.168.253.249
nameserver 192.168.253.250

domain tptlive.ee
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 veeremaa.kit16v.tpt.edu.ee

Check internet name resolutions
$ ping www.de

Postfix

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 yousurname.kit16v.tpt.edu.ee

Check that 25,110,143 ports are used:

% netstat -antp

check name resolution of you mail server from school internal dns resolvers :
% dig veeremaa.kit16v.tpt.edu.ee

# or try to ask main server
% dig @193.40.160.1 veeremaa.kit16v.tpt.edu.ee # otse nimelahendaja arvutilt

Check and change only that rows in postfix configuration:
$ nano /etc/postfix/main.cf
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 = 127.0.0.0/8 172.XXX.YYY.0/24 [::ffff:127.0.0.0]/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 0.0.0.0:25 0.0.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 vadim@veeremaa.kit16v.tpt.edu.ee

it@mail:~$ mutt -x
To: it@surname.kit16v.tpt.edu.ee
Subject:
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 !!

DOVECOT VERSIOON 2

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

listen = *, ::
login_trusted_networks = 172.16.0.0/14

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

____________________________________

DOVECOT VERSIOON 1

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

or

% /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: peeter@yousurname.kit16v.tpt.edu.ee 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