Tuesday, July 17, 2007

How do we send mail by SMTP Using Telnet Command?

Reply 1)

Step 1

Connect to the Internet in case you are a dial-up user. Open an MS-DOS prompt, and enter this command:
C:\WINDOWS>telnet mail.monitortools.com 25
This will open a Telnet window, and within a short time, you will be connected to the SMTP server, and the server says:
220 PROTAGONISTNT Mailmax version 4. 8. 3. 0 ESMTP Mail Server Ready
This varies, but you should definitely see the '220' part. It is an indication that the server is ready to service your request.
________________________________________

Step 2

Now the server expects you to identify yourself. If you are a dial-up user, you can enter the name of your computer (the one Windows asks you when you intall Windows) or anything else you want. If you have a domain-name, then you should enter the domain-name here. For eg: computer's name is dell01, so I say:
helo dell01
Note that it is 'helo' and not 'hello'. The commands are not case-sensitive, so you can also say HeLo or HELO or hELo. The server replies:
250 HELO 217.120.215.201, How you can I help?
This is like a shake-hand. You tell the server your name, and it says its name.
________________________________________

Step 3

Next give the server your e-mail address. Note that most SMTP servers require that your e-mail address belong to the same domain as the server. For example, if you send mail from Yahoo! SMTP server, you should have a Yahoo! address. You cannot use it if you give it a Hotmail address. Let me give the SMTP server some e-mail address:
mail from: webmaster@monitortools.com
'mail from:' is a SMTP command. Note that there is a space between 'mail' and 'from', followed by a colon (:). The server says:
250 Ok
________________________________________

Step 4

Tell the server who you want to send the e-mail to. Let me send a mail to info@activexperts:
rcpt to: info@activexperts.com
There are no restrictions here. You can enter any e-mail address. If there is some problem with the recipient-address, your mail will bounce, but for now, the server doesn't complain. It will say:
250 Ok
________________________________________

Step 5

You have told the server your e-mail address, and the recipient's e-mail address, so now you can go ahead and type the e-mail. You have to do that with the data command:
data
The server asks you to go ahead with your e-mail:
354 End data with .
Don't worry with the thing. It'll be explained later.
________________________________________

Step 6

Now type in your e-mail, like this:
This is a test e-mail.
Remember to type it all right. Backspace key doesn't work in Windows
Telnet, though it does in Linux. If you make a mistake, try pressing
CTRL-h. If it works, well and good.
When you finish your e-mail, press [ENTER], then a '.', and again an [ENTER]. This tells the server that you have finished the e-mail, and it can send it. It will say:
250 Ok: queued as 6AB5150038
Your mail was sent!
________________________________________

Step 7

Now you can either send another mail, or disconnect from the server. If you want to send another mail, you should repeat the 'rcpt to:' and 'data' commands. There is no need for 'helo' and 'mail from:', because the server already knows who you are. If you want to disconnect, just say 'quit':
quit
The server will reply:
221 Bye
and you will lose connection with the server

Reply 2)

Introduction

We shall again be using Telnet to talk to our remote server here, like POP. The principle behind sending an email is simple - your local computer connects to the remote mail server, talks to it using SMTP - "Simple Mail Transfer Protocol". When the mail is sent, the session is over and the remote server closes the connection.

When you use an email client like Outlook or Eudora, the mail client does all this for you. It automates the process of talking to your mail server to send and receive emails. But what if you don't have, or don't want to use, a mail client? We can use Telnet!

First choose "Run" in your Start menu and type in Telnet. Telnet is an application that allows us to communicate with remote computers. In this example, we shall be communicating with Yahoo's SMTP mail server. Choose "Remote System" from the "Connect" Menu. This will give you a box, with 3 input boxes. Type in the host name - the address of the mail server. For my Yahoo, the SMTP mail server is at smtp.mail.yahoo.com.

Now about the port: The port is a sort of a "gateway" to a computer. On the internet, each protocol, by convention has one or two port numbers assigned for itself. The HTTP connection is usually done using ports 80 and 8080; while POP transactions are done using port 110. For SMTP, port 25 is used. So type in 25 for the port.

Conversation with the Server

Now Click on connect. Once you're connected to the mail server, the mail server will respond with something like this:

220 smtp017.mail.yahoo.com ready.
Now we need to introduce ourselves to the computer and specify the sender's address. Technically, it is possible to use any SMTP server to send a mail with any server's name as the sender. This is called "Message Relaying". Since almost all servers have this feature turned off, we will simply type in the name of the SMTP server itself. [Note that you will not be able to see what you type.]

HELO smtp.mail.yahoo.com

The server will respond with:

250 Hello smtp.mail.yahoo.com, pleased to meet you.

Now we specify the sender:

MAIL From:
The server replies:

250 ... OK

There are a few observations to be made here - note that you can specify any sender here. So if you wanted to cheat the server and send bogus mail, the SMTP will not stop you - it has no security provisions. To add security, they combine the SMTP with POP authentication. So, you will have to login using the POP protocol once before using SMTP. [See Dec 2001 issue for POP mail]
Also note that whenever the server sends a message, there's a 3 digit code along with it.

For example, when it sends 250, it means that the Transaction's okay. If it's 220, it means Service Ready. If it's 500, it means there's been a syntax error in the command that you sent, and so on. There are lots of these codes, each having a specific meaning.

This is a very useful thing, as mail program using the protocol will not need to read any of the English text - they will simply read the code to understand what the response is.

Now we type in the recipient and the data, and then quit:

RCPT To:

250 ... Recipient ok

DATA

354 Enter mail, end with "." on a line by itself
From: anaplexian@yahoo.com
To: anaplexian@yahoo.com
Subject: Hi there!

This is a test message!
.

250 Mail accepted

QUIT

221 smtp.mail.yahoo.com delivering mail
[connection closed]

Take a look at the format of the email - it had a bunch of details like From, To, and Subject listed, and then I left a line and then started my email. This is because a normal email comprises of minimum two parts, the header and the body, which are separated by a blank line.

The moment you send this email and close transaction using QUIT, the mail server will send the mail off to its destination.

So now we can send email using SMTP, (and receive using POP) all without the use of a mail client or a web browser. Note that the commands we did are only a part of the whole list - there's a lot more you can do with SMTP and POP.

So next time you want to check your mail, do it the cool way - use Telnet!!

SMTP Cheat Sheet

List of Basic SMTP Commands:
HELO: identifies client

MAIL: identifies the sender of the message.

RCPT: identifies the recipient. More than one RCPT command can be issued if there
are multiple recipients.

DATA: To type in the message

QUIT: terminates conversation and closes connection.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home