You can use telnet to test Simple Mail Transfer Protocol (SMTP) communication between messaging servers. smtp is the protocol used to send email messages from one messaging server to another. using telnet can be useful if you have problems sending or receiving messages because you can manually send smtp commands to a messaging server. in return, the server will respond with responses that would be returned on a typical connection. these results can sometimes help you figure out why you can’t send or receive messages.
you can use telnet to test smtp communication for:
-
test the flow of mail from the internet to your exchange organization.
test the flow of mail from your exchange to another messaging server on the internet.
what do you need to know before you start?
-
estimated time to complete: 15 minutes
exchange permissions do not apply to the procedures in this topic. these procedures are performed on the exchange server’s operating system or on a client computer.
This topic shows you how to use the telnet client, which is included with windows. third-party telnet clients may require a different syntax than the one shown in this topic.
The steps in this topic show you how to connect to a server with an internet connection that allows anonymous connections using tcp port 25. If you try to connect to this server from the internet, you need to make sure that your exchange server is accessible from the internet at tcp port 25. Similarly, if you are trying to connect to a server on the internet from your exchange server, you need to make sure that your exchange server can open an internet connection on tcp port 25.
You may notice some Receive connectors that use TCP port 2525. These are internal Receive connectors and are not used to accept anonymous SMTP connections.
If you are testing a connection to a remote messaging server, you must run the steps in this topic on your exchange server. remote messaging servers are often configured to ensure that the ip address where the smtp connection is coming from matches the domain in the sender’s email address.
For information about keyboard shortcuts that can be applied to the procedures in this topic, see the keyboard shortcuts in the exchange admin center.
step 1: install the telnet client on your computer
In most versions of windows, you will need to install the telnet client before you can use it. to install it, see install telnet client.
step 2: find the fqdn or ip address of the destination smtp server
To connect to an smtp server using telnet on port 25, you must use the fully qualified domain name (fqdn) (for example, mail.contoso.com) or the ip address of the smtp server. If you don’t know the fqdn or ip address, you can use the nslookup command line tool to find the mx record for the target domain.
-
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 the name of the domain for which you want to find the mx record. for example, to find the mx record for the domain fabrikam.com, type fabrikam.com and then press enter.
The output of the command looks like this:
You can use any of the hostnames or ip addresses associated with the mx records as the destination smtp server. a lower preference value (preference = 10 vs. 20) indicates a preferred smtp server. multiple mx registers and different preference values are used for load balancing and fault tolerance.
When you are ready to end the nslookup session, type exit and then press enter.
step 3: telnet to port 25 to test smtp communication
In this example, we will use the following values. when you run the commands on your server, replace these values with those of the smtp server, domain, etc. of your organization.
- destination smtp server: mail1.fabrikam.com
- source domain: contoso.com
- sender email address: [email protected]
- recipient email address: [email protected]
- message subject: contoso test
- message body: this is a test message
-
Open a command prompt window, type telnet, and then press enter.
this command opens the telnet session.
type set localecho and then press enter.
This optional command allows you to see characters as you type them and may be required for some smtp servers.
type set log file <filename> and then press enter.
This optional command enables logging and specifies the log file for the telnet session. if you only specify a file name, the log file is located in the current folder. If you specify a path and filename, the path must be on the local computer, and you may need to enter the path and filename in windows dos 8.3 format (short name without spaces). the path must exist, but the log file is created automatically.
type open mail1.fabrikam.com 25 and then press enter.
type ehlo contoso.com and then press enter.
Type email from:<[email protected]> and then press enter.
write rcpt to:<[email protected]> notify = success, failure, and then press enter.
The optional notify command specifies the particular delivery status notification (dsn) messages (also known as bounce messages, non-delivery reports, or ndrs) that SMTP should provide. in this example you are requesting a dsn message for successful or failed message delivery.
type data and then press enter.
type subject: contoso test then press enter.
press enter again.
A blank line is required between the subject: field and the message body.
type this is a test message then press enter.
Type a period ( . ) and then press enter.
To disconnect from the smtp server, type quit and then press enter.
To close the telnet session, type quit and then press enter.
This is what a successful session looks like following the steps above:
step 4: telnet session success and error messages
This section provides information about the successful and failed responses to the commands used in the previous example.
smtp response codes
smtp servers respond to commands with a variety of numeric response codes in x.y.z format where:
- x indicates whether the command was good, bad, or incomplete.
- y indicates the type of response that was sent.
- z provides additional information about the command
When the server that opened the connection receives a response, it can tell if the remote server accepted the command and is ready for the next one, or if an error occurred.
The first digit (x) is particularly important to understand because it indicates the success or failure of the command that was sent. here are their possible values and their meanings.
The table above is based on information provided by rfc 5321 (Simple Mail Transfer Protocol), section 4.2.1. Additional information is included in this section and sections 4.2.2 and 4.2.3, including descriptions of the second (y) and third (z) digits of the smtp response codes.
open command
successful response: 220 mail1.fabrikam.com microsoft esmtp mail service ready at <day-date-time>
response failed: connection to mail1.fabrikam.com… could not open connection to host, on port 25: connection failed
possible error reasons:
- destination smtp service is unavailable.
- restrictions on destination firewall.
- restrictions on source firewall.
- wrong fqdn or ip destination smtp server address.
- wrong port number.
ehlo command
successful response: 250 mail1.fabrikam.com hello [<sourceipaddress>]
error response: 501 5.5.4 invalid domain name
possible error reasons:
- invalid characters in domain name.
- connection restrictions on destination smtp server.
command mail
successful response: 250 2.1.0 sender ok
error response: 550 5.1.7 invalid address
Possible error reasons: A syntax error in the sender’s email address.
failure response: 530 5.7.1 client was not authenticated
Possible reasons for the error: The destination server does not accept anonymous message submissions. You get this error if you try to use telnet to send a message directly to a Mailbox server that doesn’t have a Receive connector configured to accept anonymous connections.
welcome to command
successful response: 250 2.1.5 recipient ok
error response: 550 5.1.1 unknown user
Possible error reasons: The specified recipient does not exist.
-
-