Monthly Columns
 

SMTP with telnet

Copyright © 1999 Dru

This mini-tutorial assumes that you are fimiliar with using the RFC editor www.rfc-editor.org/rfcsearch.html and has an understanding of ports. There is a good newbie explanation of how ports work at www.whatis.com (search for ports). In FreeBSD (as in most UNIX systems), /etc/services lists the well-known ports and other commonly used ports above 1024.

This tutorial is useful for explaining the protocols at work in sending and receiving email. It is also a refreshing change for those who've always assumed that the bloat of a GUI email program was a mandatory part of the process. It can also prevent your email from piling up uncontrollably while you are still figuring out how to use sendmail and how to install qpopper!

Email is sent with SMTP (defined in RFC 821) which has been assigned the well-known port 25. Knowing this, we can use Telnet to directly connect to, and place mail directly on, any mail server in the world. The only tools required are a telnet prompt (which is available on any OS that has TCP/IP installed) and a recipient's email address. No email program, text editor, or browser required.

Let's say we want to send a message to anyuser@anyisp.net. At a command prompt simply type:

telnet mail.anyisp.net 25

Don't forget the port number. If you don't specify the port number and the sysadmin has set up any security, you'll either get an access denied message or some sort of message stating your intrusion has been monitored. If you inadvertantly forget the port number and instead get a Connected to..... message, you've just broken into that server; hopefully, you are not using that company as your ISP!

Anyways:

telnet mail.anyisp.net 25
After a moment you should get a response that includes the mail server's IP address, a Connected to message, followed by a line stating the mail program being used and the time.

In telnet, success is noted by a line beginning with 2xx, failure by 5xx.

To send your message:

mail from: <youremailaddress>

(wait for sender OK message)

rcpt to: <anyuser@anyisp.net>

(wait for recipient OK message)

data

(wait for Enter mail message)


Then type in your message.
You can type as many lines as you like
As long as your very last line
Is a period all by itself
Like this:
.

You will receive an OK message with a mail ID number

quit
leaves telnet

One note about sending mail with telnet. If you try to place mail on a server with a different address than the recipient, you will receive a "We don't relay" message. So, if your recipient is @anywhere.net, don't try to leave a message at @somewhereelse.net.

There are some other SMTP commands that are usually disabled at the mail server as they invite malicious use. Again, if your ISP has not disabled these commands, I would consider finding another ISP.

EXPN <anyname> will give the names of everyone in a mailing list

VRFY <username> will give information on a particular user

You'll notice in SMTP that there is no command to retreive mail. This is because POP is used to retreive and read email. Most mail servers and email programs use POP3 which is defined by RFC 1725 and uses port 110. Also notice that you do not need to login or provide any credentials to place a message on a mail server. This is mandatory to retreive email, so a USER and PASS command are defined in POP3.

To read your email (for free, anywhere in the world, and with only a telnet prompt):

telnet <mail.yourISP.net 110> (wait for connect message)

user <yourusername> (wait for confirmation)

pass <yourpassword> (wait for confirmation)

list (to view the number of messages)

retr <messagenumber> (to read the message; FreeBSD's scroll buffer is very useful here)

dele <messagenumber> (to delete the message)

last (to get the last message number; useful for the forgetful who receive lots of email)

quit (to leave telnet)

Dru, genisis@istar.ca