Tuesday 20 December 2011

Simple Mail Transfer Protocol


What is SMTP ? 

This appears to be a gobbledygook , right ?????
Yes , for me too ...... but only till 19th December 2011..  the day on which my educator taught me this ....
First we shall see what is the expansion of this abbreviation ,,,,it is  “Simple Mail Transfer Protocol”
Protocol  is nothing but like the ethics or rules  which has to be followed while carrying the information from  sender to receiver  ....
OK , to start with, view the diagram below .

SMTP is the protocol governing the transfer of mail from sender to the sender’s  mail server and from sender’s mail server to receiver’s mail server ...
The transfer from receiver’s mail server to the receiver, it is governed by ACCESS PROTOCOLS ....
Here we concentrate only on SMTP .........
By the way, mail server is  nothing but the server where the mails are stored ......
To put in a simple form, where SMTP plays a role, lets look at the example my educator gave ,,,

Steps  1 , 2 ,3,4 are taken care by SMTP protocol,
Step 5 taken care by access protocol (IMAP , POP)

General Architecture Of Mail Transfer :


MUA –Mail User Agent....
The MUA is the program which the user uses to read and send e-mail. It reads incoming messages that have been delivered to the user's mailbox, and passes outgoing messages to an MTA for sending.
MSA  -  Mail Submission Agent
A mail submission agent (MSA) is a computer program or software agent that receives electronic mail messages from a mail user agent(MUA) and cooperates with a mail transfer agent (MTA) for delivery of the mail. 
MTA – Mail Transfer Agent 
The MTA basically  is a software that acts as a "mail router". It accepts a message passed to it by either an MUA or another MTA, and then passes the message to the appropriate MDA for final delivery .
MDA : Mail Delivery Agent
The MDA is a software accepts a piece of mail from an MTA and performs the actual delivery.



Underlying Process :

The User types the  Email and then the send process is triggered . The Mailclient  or Mail User Agent(namely Microsoft OutLook, ThunderBird) submits the message to the MSA (Mail Submission Agent ). The MSA then transfers the message to the internal MTA(Mail Transfer Agent). You should take cognisance of the fact that all these transfer was done using SMTP protocol.
The internal MTA has the message now. Now it has to transfer the message from this internal MTA to the Mail Exchanger,because it is the one in the domain, that is incharge of the mails to be sent to the destination domain.. Where will this poor Mail exchanger get the information of the destination domain ?????????



Yes ,  the software developers are giving us another carrot . This is the facility provided to the MTA ,to  refer the MX record and find the destination domain ., For example , if it is harish@gmail.com ., the domain is gmail.com.This information is found in the MX record . So the message is transferred to gmail.com domain . Now the message is within the gmail.com domain MTA .Then this MTA , transfers the message to the MDA(Mail Delivery Agent) which performs the actual mail delivery to the mail client at the receiving end.
You should again note that , except the final part where the message  is being delivered by  MDA to the mail client  , everywhere else the  interaction takes place using SMTP.
Now lets explore the SMTP  by ourself, by trying to do what the SMTP does , using the commands.

Execute and Explore:
  1.        Get into the linux enviroinment .
  2.        Type nslookup and click enter.

What is nslookup ????????
We will come to that in a short while....For the time being remember it as name server lookup ....... Now first we shall try this....
$nslookup
The following is witnessed.



What is the > symbol ?   what has happened to the unix $ prompt ??????
This is because  nslookup is a network administration command line tool ,and  when used, we enter into the so called nslookup prompt (>) .
This is used to ask the DNS server , some questions ( QUERYING)  and getting answer from it.
If you now type the domain name collab.net . It gives the IP address of local MTA and also the IP address of the collab.net domain, which falls within this MTA . ......
 Let us now bombard it with questions ....
>set q=mx
>collab.net
We will see the following....


What does set q= mx command mean  ????????????
q -----à  query
mx ---à Mail eXchanger
So it means it is asking to get the MX record information of the collab.net domain.
This provides the information about the mail exchangers available in this domain .

What is the value 10 ????
It is the pref field . The pref (Preference) field is relative to any other MX record for the zone (value 0 to 65535). Low values are more preferred. The pref value 10 you see all over the place is just a convention you can use any number(s) you wish. The pref field is used by the SMTP (Mail) Agent to select the most preferred (lowest pref) mail server. If this mail server is unavailable (down or too busy) then if a lower preference mail server is defined (has a higher pref value) it is tried. When all defined mail servers have been tried the mail agent will then fall back to its error recovery strategy - typically an increasing time back-off algorithm over a period of 24 to 48 hours.
What is the “cylon1.sjc.collab.net” and "cylon2.sjc.collab.net" ?
These are the names of the mail exchange servers associated with Collab.net DNS.


Now select a mail exchanger from this  list and connect using telnet protocol....
>telnet cylon1.sjc.collab.net 25

By the way ,What is telnet ?
Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications.
Where ,25 is the port number , for SMTP.
Then type

helo abc.com
mail from : <abcd.com>
rcpt to: <harish.pmprk@gmail.com
data
.
from: polaris.com
subject: testmailkamesh
kamesh data
.
Note : the period (.) in the end indicates the end of the message .Then we receive an acknowledgement .




…Now click enter , and check the mail account harish.pmprk@gmail.com …we can find the mail received there in the mailbox........


So our experiment is successful ................
Note: The content in green circles is what we want the mail to reflect .It has nothing to do with the sender and receiver. You can put any Tom ,Dick and Harry 's name there..............................
Only that in red lines matter ..... rcpt to: must be a valid one ,,,mail from : can be anything...
Ok ,,,, I know what you are thinking ................
Planning to take revenge on some one whom you dont think very much of ??? by putting their name in the from address????????? .......Hmmm...I know....Ha Ha ......
Now a days people are much smarter than what we think........ So I think you will get caught........
Ok....

Now Its time for us to explore  what a name server is .......
For this, we shall execute the commands
>set q=ns
>google.com



This query is to retrieve the ns record . Where  NS –>Name server
Name server is a program or computer server that implements a name-service protocol. It maps a human readable identifier to a system-internal, often numeric, identification or addressing component.
So it means the domain name google.com is under a number of name servers . So a single domain has number of name servers . The requirement of multiple name servers aims to make the domain still functional even if one name server becomes inaccessible or inoperable.
Name server has the information about the mapping of human readable domain names to numeric (or less comprehensible) IP address .
So as we query the DNS , the DNS , passes this question to the name servers and tries to get the information. 
Let me quote to you the next area of concern ….
What happens if the name servers associated with the local DNS , does not know information about the domain name we gave  ???????????





Now if you observe, the set q=ns for google.com and collab.net….
The first one gives two sections Non authoritative answer and Authoritative answer ,, whereas in the second ,, it doesn’t do so ………..Why ??????????
Because Collabnet  is internal to our network , whereas Google is external to our network.
The fact is that , as we query ,the DNS, first query’s the internal name servers ,in a hope that the domain it is searching  for can be found there itself. As Google is not found in the interior , it query’s the external DNS server to resolve the query and gets the name servers which are capable of resolving the domain name we gave.  But our immediate local DNS does not have authority over external name server’s , So it gives the so called “UN AUTHORITATIVE answers “ indicating that our local DNS , does not have authority over the mentioned external name servers.
And so , It flings a message saying AUTHORITATIVE answers can be got from
ns1.google.com  internet address = 216.239.32.10
ns2.google.com  internet address = 216.239.34.10
ns3.google.com  internet address = 216.239.36.10
ns4.google.com  internet address = 216.239.38.10

This is what I know about SMTP ...


By ,


Harish . K













1 comment: