Thursday, September 25, 2008

How to Use Telnet to Test SMTP Communication

Using the Nslookup Command-Line Tool to Find the IP Address of an SMTP Server
To connect to a destination SMTP server by using Telnet on port 25, you must have the fully qualified domain name (FQDN) or the IP address of the SMTP server. The easiest way to find this information is to use the Nslookup command-line tool to find the MX record for the destination domain.

To use the Nslookup tool to find the IP address of an SMTP server
At a command prompt, type nslookup, and then press ENTER. This command opens the Nslookup session.

Type set type=mx and then press ENTER.

Type set timeout=20 and then press ENTER. By default, Windows DNS servers have a 15-second recursive DNS query time-out limit.

Type the name of the domain for which you want to find the MX record. For example, to find the MX record for the fabrikam.com domain, type fabrikam.com., and then press ENTER.

Note:
The trailing period ( . ) indicates a FQDN. The use of the trailing period prevents any default DNS suffixes that are configured for your network from being unintentionally added to the domain name.

The output of the command will resemble the following:

Copy Code
fabrikam.com mx preference=10, mail exchanger = mail1.fabrikam.com
fabrikam.com mx preference=20, mail exchanger = mail2.fabrikam.com
mail1.fabrikam.com internet address = 192.168.1.10
mail2 fabrikam.com internet address = 192.168.1.20

You can use any of the host names or IP addresses that are associated with the MX records as the destination SMTP server. A lower value of preference indicates a preferred SMTP server. You can use multiple MX records and different values of preference for load balancing and fault tolerance.

When you are ready to end the Nslookup session, type exit, and then press ENTER.

Note:
Firewall or Internet proxy restrictions that are imposed on your organization's internal network may prevent you from using the Nslookup tool to query public DNS servers on the Internet.
MX records are not strictly required for internal message flow inside an Exchange organization. If you have to find the FQDN of any Hub Transport server or subscribed Edge Transport server in your organization, you can use the following command in the Exchange Management Shell: Get-ExchangeServer | where {$_.isHubTransportServer -eq $true -or $_.isEdgeServer -eq $true} | Format-List Fqdn,ServerRole
For more information, see Get-ExchangeServer and Pipelining.

Using Telnet on Port 25 to test SMTP Communication
The procedure in this section shows how to use Telnet on port 25 to test SMTP communication. The procedure uses the values that are described in the following list:

Destination SMTP server mail1.fabrikam.com

Source domain contoso.com

Sender's e-mail address chris@contoso.com

Recipient's e-mail address kate@fabrikam.com

Message subject Test from Contoso

Message body This is a test message

Note:
You should always use a valid sender e-mail address so that any non-delivery report (NDR) messages that are generated by the destination SMTP server are delivered to the sender of the message.

To use Telnet on port 25 to test SMTP communication
At a command prompt, type telnet, and then press ENTER. This command opens the Telnet session.

Type set localecho and then press ENTER. This optional command lets you view the characters as you type them. This setting may be required for some SMTP servers.

Type set logfile . This optional command enables logging of the Telnet session to the specified log file. If you only specify a file name, the location of the log file is the current working directory. If you specify a path and a file name, the path must be local to the computer. Both the path and the file name that you specify must be entered in the Microsoft DOS 8.3 format. The path that you specify must already exist. If you specify a log file that doesn't exist, it will be created for you.

Type open mail1.fabrikam.com 25 and then press ENTER.

Type EHLO contoso.com and then press ENTER.

Type MAIL FROM:chris@contoso.com and then press ENTER.

Type RCPT TO:kate@fabrikam.com NOTIFY=success,failure and then press ENTER. The optional NOTIFY command defines the particular delivery status notification (DSN) messages that the destination SMTP server must provide to the sender. DSN messages are defined in RFC 1891. In this case, you are requesting a DSN message for successful or failed message delivery.

Type DATA and then press ENTER. You will receive a response that resembles the following:

Copy Code
354 Start mail input; end with .

Type Subject: Test from Contoso and then press ENTER.

Press ENTER. RFC 2822 requires a blank line between the Subject: header field and the message body.

Type This is a test message and then press ENTER.

Press ENTER, type a period ( . ) and then press ENTER. You will receive a response that resembles the following:

Copy Code
250 2.6.0 Queued mail for delivery

To disconnect from the destination SMTP server, type QUIT and then press ENTER. You will receive a response that resembles the following:

Copy Code
221 2.0.0 Service closing transmission channel

To close the Telnet session, type quit and then press ENTER.

Interpreting the Results of a Telnet Session with an SMTP Server
This section provides details about the responses that may be provided to the commands that you entered in the previous example.

Note:
The 3-digit SMTP response codes that are defined in RFC 2821 are the same for all SMTP messaging servers. The text descriptions may differ slightly for some SMTP messaging servers. In this example, the destination computer is running Exchange Server 2007.

Open mail1.fabrikam.com 25
Successful Response 220 mail1.fabrikam.com Microsoft ESMTP MAIL Service ready at

Failure Response Connecting to mail1.fabrikam.com...Could not open connection to the host, on port 25: Connect failed

Possible Reasons for Failure

The destination SMTP service is unavailable.

There are restrictions on the destination firewall.

There are restrictions on the source firewall.

An incorrect FQDN or IP address for the destination SMTP server was specified.

An incorrect port number was specified.

EHLO contoso.com
Successful Response 250 mail1.fabrikam.com Hello []

Failure Response 501 5.5.4 Invalid domain name

Possible Reasons for Failure There are invalid characters in the domain name. Alternatively, there are connection restrictions on the destination SMTP server.

Note:
EHLO is the Extended Simple Message Transfer Protocol (ESMTP) verb that is defined in RFC 2821. ESMTP servers can advertise their capabilities during the initial connection. These capabilities include their maximum accepted message size and their supported authentication methods. HELO is the older SMTP verb that is defined in RFC 821. Most SMTP messaging servers support ESMTP and EHLO.

MAIL FROM:chris@contoso.com
Successful Response 250 2.1.0 Sender OK

Failure Response 550 5.1.7 Invalid address

Possible Reasons for Failure There is a syntax error in the sender's e-mail address.

Failure Response 530 5.7.1 Client was not authenticated

Possible Reasons for Failure The destination server does not accept anonymous message submissions. You receive this error if you try to use Telnet to submit a message directly to a Hub Transport server.

RCPT TO:kate@fabrikam.com NOTIFY=success,failure
Successful Response 250 2.1.5 Recipient OK

Failure Response 550 5.1.1 User unknown

Possible Reasons for Failure The specified recipient does exist in the organization.

No comments: