Friday, August 10, 2012

Tuesday, March 06, 2012


Sending E-mail via Telnet

How to:
  • Use Telnet to connect to the SMTP server.
  • Send commands to the server to build the envelope and send a message or more
The functionality is quite similar to how a real E-mail clinet interacts with a SMTP server.

Step 1

In a Windows DOS or Command prompt, and enter:

C:\WINDOWS>telnet smtp.domain.com 25

This will open a Telnet window and connect to the SMTP server. The server responds with:

220 server5.domain.com -- Server ESMTP (SMTP Server)

The above message will be different for each server, but you should definitely get '220' response. It is an indication that the server is ready for your request.

Step 2

Now the server expects you to identify yourself. Using your computer's hostname, enter the following to identify yourself to the server. My hostname is "cronos" so I will use that:

helo cronos

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 server5.domain.com OK, [192.168.10.20].

This initiates the handshake between the server and the client. The server returns a '250' message and a hello message and your client IP address.

Step 3

Next give the server your E-mail address. Most SMTP servers require that your e-mail address belong to the same domain as the server. For example, our domain is 'domain.com' and we will use an E-mail address user@domain.com. Lets tell the SMTP server the E-mail address:

mail from: user@domain.com

'mail from:' is an SMTP command. Note that there is a space between 'mail' and 'from', followed by a colon (:). The server says:

250 2.5.0 Address Ok.

Step 4

Now we tell the server who we want to send the e-mail to. Let's send an E-mail to info@domain.com:

rcpt to: info@domain.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 2.1.5 info@domain.com OK.

Step 5

We have given the server your E-mail address, and the recipient's E-mail address, so now we 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 Enter mail, end with a single "."

Step 6

Now type 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.

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 2.5.0 Ok, envelope id 0M0H00081FQRNP10@server5.domain.com

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 will 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 2.3.0 Bye received. Goodbye.

and you will lose connection with the server.