How Email server works?


So,In other to remind myself some basic email terms and definition.I Have decided to write a blog collecting facts from different books.


 Following Informations and Diagram has been taken from
Cover image for UNIX and Linux System Administration Handbook, 5th Edition UNIX and Linux System Administration Handbook, 5th Edition by Ben Whaley; Garth Snyder; Evi Nemeth; Dan Mackin; Trent R. Hein Published by Addison-Wesley Professional, 2017

 Link: https://www.safaribooksonline.com/library/view/unix-and-linux/9780134278308/Email.xhtml#_idParaDest-169


Mail system architecture


A mail system consists of several distinct components:
  1. A “mail user agent” (MUA or UA) that lets users read and compose mail
  2. A “mail submission agent” (MSA) that accepts outgoing mail from an MUA, grooms it, and submits it to the transport system
  3. A “mail transport agent” (MTA) that routes messages among machines
  4. A “delivery agent” (DA) that places messages in a local message store (the receiving users’ mailboxes or, sometimes, a database)
  5. An optional “access agent” (AA) that connects the user agent to the message store (e.g., through the IMAP or POP protocol)


User agents

Email users run a user agent (sometimes called an email client) to read and compose messages.

The MSA

 is a sort of “receptionist” for new messages being injected into the system by local user agents. An MSA sits between the user agent and the transport agent and takes over several functions that were formerly a part of the MTA’s job
Transport agents A transport agent must accept mail from a user agent or submission agent, understand the recipients’ addresses, and somehow get the mail to the correct hosts for delivery.

Local delivery agents

A delivery agent, sometimes called a local delivery agent (LDA), accepts mail from a transport agent and delivers it to the appropriate recipients’ mailboxes on the local machine.

Message stores

A message store is the final resting place of an email message once it has completed its journey across the Internet and been delivered to recipients.
Mail has traditionally been stored in either mbox format or Maildir format. The former stores all mail in a single file, typically /var/mail/username, with individual messages separated by a special From line. Maildir format stores each message in a separate file.

Access agents

Two protocols access message stores and download email messages to a local device (workstation, laptop, smartphone, etc.): Internet Message Access Protocol version 4 (IMAP4) and Post Office Protocol version 3 (POP3).

Anatomy of a mail message

A mail message has three distinct parts:

  1. Envelope
  2. Headers
  3. Body of the message
Following lines have been taken from the Book Linux Mail 
Cover image for Linux E-mail Linux E-mail by Magnus Back; Ralf Hildebrandt; Carl Taylor; Ian Haycox; Patrick Ben Koetter; David Rusenko; Alistair McDonald
Link:   https://www.safaribooksonline.com/library/view/linux-e-mail/9781847198648/ch01s04.html

Main e-mail protocols: SMTP, POP, and IMAP

In the UNIX environment, traditional mail applications did not use any network protocol at all. They have instead accessed the locally stored mailbox files directly through the file system. Typically, the inbox of each user is stored in a single file in either the /var/mail or the /var/spool/mail directory with the same name as that of the user (for example, /var/spool/mail/joe).

The most important protocol in Internet mailing is the Simple Mail Transfer Protocol (SMTP). Its purpose is to transport e-mail messages between two systems.

To collect new messages, the end user does not utilize SMTP. This is where the Post Office Protocol (POP) and the Internet Message Access Protocol (IMAP) come in.

POP protocol
 It focuses on giving the users access to their inboxes, from which the users can download the new messages to their local computers and then delete them from the server


IMAP protocol
IMAP is meant as an access method to a first class mail store, that is, it is designed to allow the user to store the messages permanently on the server. This solves the System Administrator's backup problem and allows the user to access all messages from any place in the world (firewall restrictions aside). IMAP also has a more widespread implementation of TLS-secured connections, making IMAP safe to use in hostile environments

The SMTP protocol
SMTP is a line-oriented text protocol that runs over TCP


220 mail.example.com ESMTP Postfix (2.12.6.2)
EHLO gw.example.net
250-mail.example.com
250-PIPELINING
250-SIZE
250-VRFY
250-ETRN
250 8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
MAIL FROM:<jack@example.net> SIZE=112
250 Ok
RCPT TO:<jill@example.com>
250 Ok
RCPT TO:<jack@example.com>
250 Ok
RCPT TO:<joe@example.com>
550 <joe@example.com>: Recipient address rejected: User unknown in local recipient table
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Test mail
To: <root@example.com>
Date: Sun, 15 May 2009 20:23:22 +0200 (CEST)
This is a test message.
.
250 Ok: queued as B059D3C2B
QUIT
221 Bye


Explanation:
gw.example.net connecting to an SMTP server that calls itself mail.example.com. Because the server's first response contains ESMTP, the client decides to try Enhanced SMTP (ESMTP) and greets the server with EHLO instead of HELO.
The attribute to indicate the size of the message to the server is defined by SIZE.
SMTP message can obviously have more than one recipient.
The message is accepted by the server and queued for delivery (
If the message cannot be delivered, the server will send a non-delivery message (bounce) back to the sender.
In response to the message contents the server must either reject the message for all recipients or accept it for all recipients.


The envelope of a message consists of the information given in the MAIL FROM and RCPT TO commands, that is, the sender and recipient information that are used to deliver the message. An SMTP server pays no attention what so ever to the From, To, and Cc message headers. In our example the To header contains just a single address with no other relation to the actual recipient addresses than the domain, but that is just a coincidence. Bounces are always sent to the envelope sender address, in this case jack@example.net. The sender address of bounce messages is the empty sender address, often called the null sender.

Numerical codes given by the server at the beginning of each line. Each number has a specific meaning and it is important to learn the correct interpretation of the first digit.


2
Server has accepted the previous command and is awaiting your next command.
3
Used only in response to the DATA command, and means that the server is ready to accept the message contents.
4
Temporary error: The request cannot be performed at the moment, but it may be successfully serviced later.
5
Permanent error: The request will never be accepted.

Disclamer :ALL the information above are from the respected writers book I have provided their links and Acknowlede that the rights belong to them.I have just included the above information for recalling in future and to share the information with others.




















Comments

Popular Posts