Thursday, December 18, 2008

SMTP

Documents to read:

1. After the installation of the softwares, read the manuals with a
browser, such as [lynx].

$ lynx /usr/share/doc/exim/manual.html/oview.html

2. Manual of exim[8].

$ man 8 exim

3. Read HOWTO documents

$ zless /usr/share/doc/HOWTO/en-txt/Mail-Administrator-HOWTO.gz


4. Exim - The Mail Transfer Agent By Philip Hazel ( O'REILLY )


The following simplified block diagram shows how email goes from one
user to another.

sender -> MUA -> mail-spool -> MTA ->-
|
|TCP connection
|(localhost/network)
|
recipient <- MUA <- mailboxes <- MTA <-

Sender uses a Mail User Agent( MUA ) to submit mail to mail spool. The
Mail Transport Agent( MTA ) takes the mail from spool, establishes TCP
connection to the destination MTA and transfers the mail using SMTP
protocol. The MTA at sender's end is the client and the MTA at the
receiving side is the server in this situation. The receiving side MTA
takes the mail and stores it in the user's mailbox. MTA can function
both as a server and as a client.

Examples of MUA - mail, mutt, pine, elm etc etc
Examples of MTA - sendmail, exim, postfix, qmail etc etc.

SMTP - Simple Mail Transfer Protocol - SMTP is used to transfer
millions of email daily around the globe. An extended SMTP,
known as ESMTP is widely used. ESMTP is backward compatible
with SMTP

The basic operation of SMTP server ( Port 25 ) are:

1. Accept an incoming message
2. Check the addresses of the message
3. If the recipient is local, store the message for retrieval
4. If the recipient is remote, forward the message
5. If the message is undeliverable, return an error message to the
sender, explaining the problem

In this experiment [exim] is to be installed as MTA.

Create a directory [ mail ] in your home directory and carry out the
mail related experiments in that directory.
$ mkdir $HOME/mail

Bring the files
exim_3.35-1woody3_i386.deb - CD1
exim-doc-html_3.20-1_all.deb - CD4
libmailutils0_20020409-1_i386.deb - CD1
mailutils_20020409-1_i386.deb - CD1

in [mail] directory from anonymous FTP server of your laboratory.

Installation of SMTP server:
Some free Mail Transport Agents ( SMTP
servers) are available. Among them [sendmail] is most widely used but
it has complex configuration options. In this experiment, another MTA,
[exim] is to be installed. A VERY simple configuration of [exim] is to
be tested on Debian Linux platform.

Note: At present [exim] MTA is being used at CEMK.

Check status of installed MTA
$ dpkg -l | grep MTA

Remove installed MTA and its configuration file
# dpkg --purge sendmail
or
# dpkg --purge exim

However due to complex dependency among different files and programs,
removal of installed MTA is difficult. Remove the packages which are
preventing removal of the MTA.


Install [exim] binary
# dpkg -i ./exim_3.35-1woody3_i386.deb

Install exim documentation
# dpkg -i ./exim-doc-html_3.20-1_all.deb

Do not configure [exim] now. Select option (5) (No configuration)

A minimal configuration file is available. See that file
$ zless /usr/share/doc/exim/example.conf.gz

Save this file as [/etc/exim/my-conf]
# zcat /usr/share/doc/exim/example.conf.gz > \
> /etc/exim/my-conf

Edit [/etc/exim/my-conf]
--------------------- /etc/exim/my-conf ------------------------

# MAIN CONFIGURATION

primary_hostname = cc-146.cc.cemk.ac.in

local_domains = localhost : cc-146.cc.cemk.ac.in : cc-146

kkk # planted error

end

# TRANSPORTS CONFIGURATION

remote_smtp:
driver = smtp

local_delivery:
driver = appendfile
file = /var/mail/$local_part
delivery_date_add
envelope_to_add
return_path_add
group = mail
mode = 0660

address_pipe:
driver = pipe
return_output

address_file:
driver = appendfile
delivery_date_add
envelope_to_add
return_path_add

address_reply:
driver = autoreply

end



# DIRECTORS CONFIGURATION

system_aliases:
driver = aliasfile
file = /etc/aliases
search_type = lsearch
# user = exim
file_transport = address_file
pipe_transport = address_pipe

userforward:
driver = forwardfile
file = .forward
no_verify
no_expn
check_ancestor
# filter
file_transport = address_file
pipe_transport = address_pipe
reply_transport = address_reply


localuser:
driver = localuser
transport = local_delivery

end


# ROUTERS CONFIGURATION

lookuphost:
driver = lookuphost
transport = remote_smtp
ignore_target_hosts = 127.0.0.0/8

end



# RETRY CONFIGURATION

* * F,2h,15m; G,16h,1h,1.5; F,4d,8h

end

# REWRITE CONFIGURATION
# There are no rewriting specifications in this default
# configuration file.

end



# AUTHENTICATION CONFIGURATION
# There are no authenticator specifications in this default
# configuration file.

# End of Exim configuration file
----------------------------------------------------------------
Check syntax of this file if used as [exim] configuration file.

# /usr/sbin/exim -C /etc/exim/my-conf -bV

Remove errors if any and recheck

# /usr/sbin/exim -C /etc/exim/my-conf -bV


Start [exim]. It may not start in absence of a configuration file
# /etc/init.d/exim start


Copy [my-conf] as exim's configuration file.
# cp /etc/exim/my-conf /etc/exim/exim.conf

Start [exim].
# /etc/init.d/exim start


Install a simple MUA
# dpkg -i libmailutils0_20020409-1_i386.deb
# dpkg -i mailutils_20020409-1_i386.deb

Request your friends to send mail to you
friend $ mail sumit@cc-146 < /etc/resolv.conf
friend $ mail sumit@cc-146.cc.cemk.ac.in < /dev/null

Stop [exim].
# /etc/init.d/exim stop



Option [ -bd ] runs exim as daemon. With [ -q 2m ], the mail queue is
processed at intervals of two minutes. This value is not suitable for
real applications.

Though [sendmail] MTA is not installed, the following link is used to
point to the [exim] binary. Due to this link, [ exim ] can be started
using the method of starting [sendmail].

$ file /usr/lib/sendmail
Output->

Start exim using the above link.
# /usr/lib/sendmail -q1h10m

It is possible to communicate with MTA directly, using raw SMTP
commands, over a telnet session to Port 25. Port 25 is assigned to
SMTP. You may check [/etc/services].


Sending mail using raw SMTP commands:

Initiate a telnet session on Port 25 of your host, to talk to MTA
using raw SMTP commands.

$ telnet 172.16.2.145 25
Replace 172.16.2.145 with Ethernet interface of your machine.


A portion of typical screen output for this example is shown below.
The texts without a leading number are commands executed by you. The
MTAs at the two ends use these leading numbers for communication.

Examples:
220 is the greeting message.
500 is one error message

$ telnet 172.16.2.146 25
Trying 172.16.2.146...
Connected to 172.16.2.146.
Escape character is '^]'.
220 cc-146.cc.cemk.ac.in ESMTP Exim 3.35 #1 Mon, 17 Mar 2006 18:32:13
+0530
ehlo cc.cemk.ac.in
250-cc-146.cc.cemk.ac.in Hello sumit at cc.cemk.ac.in [172.16.2.146]
250-SIZE
250-PIPELINING
250 HELP
help
214-Commands supported:
214- HELO EHLO MAIL RCPT DATA AUTH
214 NOOP QUIT RSET HELP
mail from: sumit@cc-146
250 is syntactically correct
rcpt to: guest@cc-146
250 is syntactically correct
data
354 Enter message, ending with "." on a line by itself
This is test mail... sumit
.
250 OK id=1FKb9W-0000KY-00
quit
221 cc-146.cc.cemk.ac.in closing connection
Connection closed by foreign host.

Check the mail of [guest].
# mail -u guest


Send a mail to a friend in another host using SMTP commands.
Was it successful ? ( Y / n )


Mail aliases:

User [ sumit ] wants to receive mail as [ sumit ], [ sumitbasu ],
[ sumit-basu ] and [ sumit_basu ]. This can be done with the help of
aliasing.
Replace [ sumit ] with your-log-name.

Edit [/etc/mail/aliases] as under. Replace [sumit] with your-log-name.

#.. [/etc/mail/aliases] ...
sumitbasu: sumit
sumit-basu: sumit
sumit_basu: sumit
#.. [/etc/mail/aliases] ...


Build the alias database file from the alias text file. Typical screen
output is also shown.
# exim_dbmbuild /etc/aliases /etc/aliases.db
3 entries written

Verify the aliases users.
# /usr/sbin/exim -bv sumitbasu
sumit@cc-146.cc.cemk.ac.in verified

# /usr/sbin/exim -bv sumit-basu
sumit@cc-146.cc.cemk.ac.in verified

# /usr/sbin/exim -bv sumit_basu
sumit@cc-146.cc.cemk.ac.in verified

# /usr/sbin/exim -bv sumit
sumit@cc-146.cc.cemk.ac.in verified

Request a friend to send a mail to sumit_basu
$ mail sumit_basu@cc-146.cc.cemk.ac.in < /dev/null


Group mails:

The alias mechanism can be used to send mails to a group of users.


Edit [/etc/mail/aliases] as under
------- /etc/mail/aliases -------
sumitbasu: sumit
sumit-basu: sumit
sumit_basu: sumit
3year: :include:/etc/exim/3y
---------------------------------


Edit file [/etc/exim/3y] as under.
------ /etc/mail/3y ------
sumit@cc-140.cc.cemk.ac.in
sunil@cc-145.cc.cemk.ac.in
you@localhost
--------------------------


Build the alias database file from the alias text file.
# exim_dbmbuild /etc/aliases /etc/aliases.db
4 entries written

Check the user [3year]
# /usr/sbin/exim -bv 3year

Send a mail to the group...

$ mail -v 3year
Subject: Group Mail
Testing group mail
.
Cc:

Request the recipients to check their mails.

----------