Thursday, August 18, 2011

Email Fundamentals: How to Send Email via Telnet

This is one of the essential troubleshooting tricks that an Exchange administrator needs to know, sending an email using Telnet from the command line.

Let’s say you’ve just configured a relay connector and want to test it from the server that you wish to allow relay from before you let that server’s owner know that it is all set up for them. Or perhaps you want to quickly test whether a another email server on the internet is accepting mail from your network.

For just about any scenario where you want to quickly test SMTP knowing this method is very useful.

Note: this technique requires the Telnet client to be installed on the computer you’re running the test from. For Windows XP and Windows Server 2003 it will already be installed, but Windows 7 and Windows Server 2008 need to install it first.

Installing the Telnet Client for Windows 7

To install the Telnet client on a Windows 7 computer use these steps.

  1. Open the Control Panel
  2. Click on Programs
  3. Click on Turns Windows Features on or off
  4. Scroll down the list until you see Telnet Client, and tick that box
  5. Click OK and close the Control Panel

Installing the Telnet Client for Windows Server 2008

To install the Telnet client on a Windows Server 2008 computer open a command prompt and run the following command.

C:\>servermanagercmd -i telnet-client
.........

Start Installation...
[Installation] Succeeded: [Telnet Client].

Success: Installation succeeded.

Installing the Telnet Client for Windows Server 2008 R2


To install the Telnet client on a Windows Server 2008 R2 computer open a PowerShell window and run the following command.

PS C:\> Import-Module servermanager
PS C:\> Add-WindowsFeature telnet-client

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Telnet Client}

Sending Email from the Command Line via Telnet


Open a command prompt and use Telnet to connect to the remote email server on port 25.

C:\>telnet esp-ho-ex2010a 25

If Telnet is able to connect to the remote server you should see its welcome banner.

220 ESP-HO-EX2010A.exchangeserverpro.net Microsoft ESMTP MAIL Service ready at T
ue, 9 Aug 2011 22:00:04 +1000

The first command to send is the HELO command. Some email servers will accept HELO on its own, others will require you to also provide a host or domain name along with it.

helo test.com
250 ESP-HO-EX2010A.exchangeserverpro.net Hello [10.0.1.11]

Next use the MAIL FROM command to tell the remote server who the email is from.

mail from: test@test.com
250 2.1.0 Sender OK

Now use the RCPT TO command to tell the remote server who to deliver the email to.

rcpt to: alan.reid@exchangeserverpro.net
250 2.1.5 Recipient OK

The final step for the bare minimum set of commands is the DATA command.

data
354 Start mail input; end with .

If you just want to send a blank message type a period “.” and press enter. Otherwise you can set a subject line for the message if you like. Use SUBJECT and then type your subject line, and press enter.

subject: this is a test message

Type any text you want to include with the message, press enter, and then finally type a period “.” and press enter to send the email.

sending a test message via telnet
.
250 2.6.0 [InternalId=320] Queued mail for delivery

If the message was queued for delivery then it has been accepted by the server. If this is an Exchange server that you control then you can use message tracking to troubleshoot further if the message doesn’t make it to the inbox that you were expecting.

Type the QUIT command to terminate the connection when you’re done.

SMTP Status Codes


You may notice along the way that after typing commands you see responses from the server starting with “250″.

250 is a good thing, and there are a lot of other SMTP status codes you’ll encounter the more you use this technique. For example an email server may deny your attempt to relay mail between two domains.

550 5.7.1 Unable to relay

Or you may encounter an email server that is explicitly blocking email from your domain.

554 5.1.0 Sender denied

There are a lot of different scenarios you might encounter here, and thankfully the SMTP status codes will help you troubleshoot them.

Now that you understand how to send email using Telnet and the command line I hope you find this technique very useful in the future.

0 comments

Post a Comment