Using Telnet to Send Email

Following up on from my previous post about using telnet to check your email, here’s how you can use telnet to send an email.

There is one very important difference between checking your email and sending an email. Due to the huge amount of spam being sent every day, most ISP’s require that you use their email server to send email. So before you can send an email, you’ll need the name of your ISP’s SMTP server. If you don’t know it, and you’re using either Linux or MacOS X, you can use the nslookup command line utility to find it. Here’s how:

  • Open a command prompt,
  • Type nslookup, and hit enter,
  • Type set querytype=mx, followed by enter,
  • Type the domain name for your isp, i.e., isp.net, hit enter.
  • nslookup will return the mail exchanger address for your isp,
  • Type exit to quit nslookup.

If you don’t have access to nslookup you may be able to guess it from the ISP’s domain name. Taking the ISP domain name to be isp.net:

  • mail.isp.net
  • smtp.isp.net

Now that you have the SMTP server address, you can start sending email. Back to your command prompt and run the following command:

telnet mail.isp.net 25

Once you have connected to the SMTP server, you’ll need to tell it who you are, so type:

helo localhost

You should get a response similar to:

250 mail.isp.net helo localhost [Your IP Address]

Unlike sending email, you don’t need a username and password to login. The next step is to tell the server the email address you’re sending from:

mail from:[Your Email Address]

If the address is accepted by the server you should see:

250 OK

Now tell it the address that you want to email:

rcpt to:[Recipients Email Address]

Once again, if the address is accepted the server will tell you with:

250 Accepted

Now it’s time to start writing your email. You tell the server that you’re ready with this command:

data

All going well, the server will respond with:

354 Enter message, ending with "." on a line by itself

Before you can write the actual message content, you need to provide a couple of headers for the email. Not including some basic headers could result in your email being classified as spam, resulting in it being rejected by the recipient. The basic headers to include are Date, From, To, and Subject, as follows:

Date: [Todays Date & Time]From: [Your Email Address]To: [Recipients Email Address]Subject: [Your Email Subject]

Just before starting the content of your email, hit enter to leave a blank line, then start typing!

When you are finished writing your email, hit enter to leave a blank line, type a “.” (no quotes), and hit enter a again. The server should respond with:

250 OK [Message ID]

And that’s it, your message will be queued by the email server and sent on to your recipient.