Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Demystify electronic mail.

Posted on 1998-01-05
Medium Priority
Last Modified: 2010-03-18
Question by:msvenkat
  • 2

Expert Comment

ID: 1587257
This is a fairly open-ended question, so I am giving this as a comment.
Email is transmitted to its destination through one or more
MTA (mail transport agents). (A "destination" is a mailbox here.
The recipient then may use a program to fetch their mail
from the mailbox, that's a different story.)
The most widely used (but not the only one) MTA is sendmail.
It can act both as a daemon for mail delivery and as a one-time
mail sending program.
The communication between MTA's is done in SMTP (a protocol written on top of TELNET, with just a couple of commands).
Here is a typical case:

Suppose you are me@here.net and you use pine or elm or mail
to send a message to them@there.net. Neither of those programs
actually does the communication to other hosts (at least not in their default configuration; maybe they can be configured to do so? I wouldn't know). They all invoke create a file containing
your message with appropriate headers and invoke "sendmail" to send it. Your local "sendmail" establishes a connection to host
there.net, TCP port 25 (the standard SMTP port) (name resolving is done transparently to the program with the gethostbyname() call, same as in telnet, ftp and many other programs, it's up to the OS to care whether it's via DNS or via /etc/hosts or via yellow pages.) At there.net, another "sendmail" (this time as a daemon) is listening to connections on port 25. It receives the message from your local "sendmail", determines its recipient is local, and appends the message to them's mailbox. In more complex cases, it is possible for a message to path through several MTA's (similar to IP packet routing).
It is possible to write your own mailer program that won't use a local MTA, but send the message directly to a remote MTA
(By the way, it is not necessary for your program to parse the recipient's address to determine what host to contact. It is possible to contact any MTA in the world and let it do the work. For example, my Netscape mailer always sends mail through mail.iname.com.)
Normally, a mail application incorporates mail sending capabilities and mail reading capabilities. As for mail reading, there are more possibilities, because there are different ways to access one's mailbox - local spool, POP, IMAP...

Expert Comment

ID: 1587258
Actually, I just realized I was wrong about name resolving.
gethostbyname() is fine if there.net is a host, but if it's a domain, then you'll need a DNS query to find that domain's mail exchange server (where an MTA is running). Functions for that purpose are declared in <resolv.h>. You don't have to be running a DNS locally, just be able to access a DNS - i.e. have an appropriate line in /etc/resolv.conf. If you can type, e.g., "ftp ftp.gnu.ai.mit.edu" and get connected, then everything's okay.
If not, ask your ISP / LAN admin / whomever for a DNS address and put a line like this in your /etc/resolv.conf:
nameserver xx.yy.zz.tt
If you really want to set up a local DNS (though it is absolutely unnecessary for your purpose), DNS-HOWTO may be of help.
LVL 32

Accepted Solution

jhance earned 1600 total points
ID: 1587259
How does an email work?

An email is an electronic transmission (usually following a defined standard) from a sender to a recipient.

What is the work of an email client and a server?

A CLIENT is the program that the sending or receiving persons use to compose and read their emails.  A server is a program which manages the delivery and queuing of mail to and from client programs.  Normally you will interact with a client program and IT will talk to a server program.

Is Pine, Elm email clients ?

Yes, these are examples of EMAIL clients.  Also you might add Eudora, Outlook, Netscape Mail, Pegasus, the ubiquitous unix mail.

Whose job is to establish the connection with the remote machine. Are the clients the one that establish connection with the remote server as specified on the address part of the mail or is it the server.

The client program will establish a connection with it's local mailer.  This is normally assigned by your service provider and may be something like mail.myhost.com or smtp.myhost.com.  This is a server that will accept your mail, determine what to do with it and then either deliver it, pass it off to another server that can deliver it, or bounce it back to you.

If it is the client then what is the job of the sendmaail deamon?

SENDMAIL is one example of a server program for handling internet mail.  Other examples would be SMAIL, MDAEMON, MS Exchange.

A mailer is usually something that handles some step in the delivery of mail.  On a unix system, sendmail may call other programs to deliver a message to the users mailbox, or route it through a dial-up modem.  These "helper" programs are often called mailers.  Sendmail itself has capabilities which also classify it as a mailer.

How should I find the destination machine address. Should I query the DNS server. Are there any simple functions for doing so.I don't even know whether a DNS server is running or not. If it is not how should I set one to run.

No, you don't query the DNS database yourself.  This is the job of the server (sendmail).  It finds out there joeblow.com is and what is the best way to get it there.

Moreover what happens when Pine/elm says that the "Message has been sent". Has it really sent the mail to the desired deestination ? I heard that it puts thhe mail in a spooling area. Isn't this misleading the sender? Is there any way to overcome this.

When pine/elm says it was sent, it means that it has handed the message off successfully to the server.  It does not mean that the message has been delivered to the recipient.  Under the current Internet mail system, there is NO SUCH THING as guaranteed mail delivery.

I am trying to build an email client and server. Do suggest me some good books/web sites holding info on the same.I have downloaded the necessary RFC's but they are difficult to comprehend.

I'd start with the client and take a look at the POP-3 (Post Office) Protocol.  It is very widely used and is quite simple to understand and implement.  You can connect you one like this:

telnet mymailhost.myserver.com 110

This will connect to the POP3 server (IP port 110) on your host.

Author Comment

ID: 1587260
Thank you for the answer. I accept that sendmail is an MTA. In order to
test that I did'nt invoke the sendmail deamon. Even after that I am able to
deliver mails without any problem. But I tried that only within my host.
So please give a solution to my problem.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question