Monthly Archives: January 2008

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.,, 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


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

telnet 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 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:


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.

Using .htaccess to Block Spam Bots

Following on from my attempts to block trackback spam, here’s another way to block those pesky spam bots. This only works if your server uses Apache.

Because this only works on Apache, you may have already guessed that it uses the .htaccess file to prevent the spam bot from reaching your page. In order to block a spam bot, you’ll need to know the User Agent for the bot. The User Agent can be found from your web stats package. If you’re using WordPress, then you can use any of the available stats packages to find the user agents hitting your site. (I use FireStats and StatPress.)

Before you edit your .htaccess a word of warning:


Be very sure of what you’re doing.


Because .htaccess controls access to your website, you could find yourself locked out of your own website. If that happens, you’ll need to contact your hosting provider and ask them to make the changes for you.

Once you’re ready to edit your .htaccess file, open your preferred text editor and save a blank file as htaccess. Notice that there is no dot in front of the name. The reason for this is that most modern OSes will hide any file with a filename starting with a dot, and you’ll need to be able to find the file later on.

At the top of your new htaccess file type the following:

SetEnvIfNoCase User-Agent "^User Agent To Be Blocked" bad_bot

If you want to block more than one User Agent, then add the above line for each spam bot to be blocked.

Under this, you’ll need to add the following lines:

<Limit GET POST>Order Allow,DenyAllow from allDeny from env=bad_bot</Limit>

Save the changes you’ve just made, and fire up your preferred FTP program. Upload the file to the root directory of your website or blog using the ASCII file type. Once the file has been upload, use your FTP program to rename the file to .htaccess.

Check your website to ensure that you can access it, and you’re good to go!