Demystify electronic mail.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 and you use pine or elm or mail
to send a message to 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, 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, 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
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...
Actually, I just realized I was wrong about name resolving.
gethostbyname() is fine if 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" 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:
If you really want to set up a local DNS (though it is absolutely unnecessary for your purpose), DNS-HOWTO may be of help.
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 or  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 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 110

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msvenkatAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.