在 Exchange 伺服器上使用 Telnet 測試 SMTP 通訊Use Telnet to test SMTP communication on Exchange servers

您可以使用 Telnet 來測試簡易郵件傳輸通訊協定 (SMTP) 郵件伺服器之間的通訊。You can use Telnet to test Simple Mail Transfer Protocol (SMTP) communication between messaging servers. SMTP 是用來將電子郵件訊息從一部郵件伺服器傳送到另一部的通訊協定。SMTP is the protocol that's used to send email messages from one messaging server to another. 如果您無法傳送或接收郵件,則使用 Telnet 會非常有用,因為您可以手動傳送 SMTP 命令到郵件伺服器。Using Telnet can be helpful if you're having trouble sending or receiving messages because you can manually send SMTP commands to a messaging server. 在 [傳回] 中,伺服器會以一般連線傳回的回應回復。In return, the server will reply with responses that would be returned in a typical connection. 這些結果有時候會協助您找出為何無法傳送或接收郵件。These results can sometimes help you to figure out why you can't send or receive messages.

您可以使用 Telnet 測試 SMTP 通訊,以進行下列作業:You can use Telnet to test SMTP communication to:

  • 測試從網際網路到您的 Exchange 組織的郵件流程。Test mail flow from the Internet into your Exchange organization.

  • 測試從您的 Exchange 到網際網路上之另一部郵件伺服器的郵件流程。Test mail flow from your Exchange to another messaging server on the Internet.

提示

您知道,[!注意事項] 您可以使用 Microsoft Remote Connectivity Analyzer,而不是使用 Telnet 來測試 SMTP 連線能力 https://testconnectivity.microsoft.com/Did you know that, instead of using Telnet to test SMTP connectivity, you can use the Microsoft Remote Connectivity Analyzer at https://testconnectivity.microsoft.com/? 透過 Remote Connectivity Analyzer,您可以選擇想要執行的連線測試,在此例中為 輸入 SMTP 電子郵件,並遵循所顯示的指示。With the Remote Connectivity Analyzer, you can choose the connectivity test you want to do, in this case Inbound SMTP Email, and follow the instructions shown. 它會逐步引導您完成您需要輸入的資訊,並為您執行測試,然後為您提供結果。It'll step you through the information you need to enter, run the test for you, and then give you the results. 請嘗試!Give it a try!

開始之前有哪些須知?What do you need to know before you begin?

  • 預估完成時間:15 分鐘Estimated time to complete: 15 minutes

  • Exchange 權限無法套用於此主題的程序。Exchange permissions don't apply to the procedures in this topic. 在 Exchange 伺服器或用戶端電腦的作業系統中執行這些程式。These procedures are performed in the operating system of the Exchange server or a client computer.

  • 本主題說明如何使用 Telnet 用戶端(包含在 Windows 中)。This topic shows you how to use Telnet Client, which is included with Windows. 協力廠商的 Telnet 用戶端可能需要與本主題所顯示的語法不同的語法。Third-party Telnet clients might require syntax that's different from what's shown in this topic.

  • 本主題中的步驟將告訴您如何連線至網際網路對向的伺服器,允許使用 TCP 埠25進行匿名連線。The steps in this topic show you how to connect to an Internet-facing server that allows anonymous connections using TCP port 25. 如果您嘗試從網際網路連線到此伺服器,您必須確定您的 Exchange 伺服器可從網際網路上的 TCP 埠25上獲得。If you're trying to connect to this server from the Internet, you need to make sure your Exchange server is reachable from the Internet on TCP port 25. 同樣地,如果您嘗試從 Exchange 伺服器從網際網路前往伺服器,您必須確定您的 Exchange 伺服器能夠開啟 TCP 埠25上的 [連線到網際網路]。Similarly, if you're trying to reach a server on the Internet from your Exchange server, you need to make sure your Exchange server can open a connect to the Internet on TCP port 25.

  • 您可能會注意到,有些使用 TCP 埠2525的接收連接器。You might notice some Receive connectors that use TCP port 2525. 這些是內部接收連接器,不會用來接受匿名 SMTP 連線。These are internal Receive connectors and aren't used to accept anonymous SMTP connections.

  • 若要在遠端郵件伺服器上測試連線,您應該在 Exchange 伺服器上執行本主題中的步驟。If you're testing a connection on a remote messaging server, you should run the steps in this topic on your Exchange server. 遠端郵件伺服器通常會加以設定,以確保 SMTP 連線所在的 IP 位址符合寄件者電子郵件地址中的網域。Remote messaging servers are often set up to make sure the IP address where the SMTP connection is coming from matches the domain in the sender's email address.

  • 如需適用於此主題中程序的快速鍵相關資訊,請參閱 Exchange 系統管理中心的鍵盤快速鍵For information about keyboard shortcuts that may apply to the procedures in this topic, see Keyboard shortcuts in the Exchange admin center.

提示

有問題嗎?請在 Exchange 論壇中尋求協助。請造訪下列論壇:Exchange ServerExchange OnlineExchange Online ProtectionHaving problems? Ask for help in the Exchange forums. Visit the forums at: Exchange Server, Exchange Online, or Exchange Online Protection.

步驟1:在您的電腦上安裝 Telnet 用戶端Step 1: Install the Telnet Client on your computer

在大多數 Windows 版本中,您必須先安裝 Telnet 用戶端,才能加以使用。On most versions of Windows, you'll need to install the Telnet client before you can use it. 若要進行安裝,請參閱安裝 Telnet 用戶端To install it, see Install Telnet Client.

步驟2:尋找目的地 SMTP 伺服器的 FQDN 或 IP 位址Step 2: Find the FQDN or IP address of the destination SMTP server

若要在通訊埠25上使用 Telnet 連接至 SMTP 伺服器,您必須使用完整功能變數名稱 (FQDN) (例如,mail.contoso.com) 或 SMTP 伺服器的 IP 位址。To connect to an SMTP server by using Telnet on port 25, you need to use the fully-qualified domain name (FQDN) (for example, mail.contoso.com) or the IP address of the SMTP server. 如果您不知道 FQDN 或 IP 位址,您可以使用 Nslookup 命令列工具來尋找目的網域的 MX 記錄。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 destination domain.

注意

網路原則可能會使您無法使用 Nslookup 工具來查詢網際網路上的公用 DNS 伺服器。Network policies might prevent you from using the Nslookup tool to query public DNS servers on the Internet. 或者,您可以在網際網路上使用任意一種可自由使用的 DNS 查閱或 MX 記錄查閱網站。As an alternative, you can use one of the freely-available DNS lookup or MX record lookup web sites on the Internet.

  1. 在命令提示字元中輸入 nslookup ,然後按 enter 鍵。At a command prompt, type nslookup, and then press Enter. 此命令會開啟 Nslookup 工作階段。This command opens the Nslookup session.

  2. 類型 set type=mx ,然後按 enter。Type set type=mx, and then press Enter.

  3. 輸入要尋找其 MX 記錄的網域名稱。Type the name of the domain for which you want to find the MX record. 例如,若要尋找 fabrikam.com 網域的 MX 記錄,請輸入 fabrikam.com. ,然後按 enter。For example, to find the MX record for the fabrikam.com domain, type fabrikam.com., and then press Enter.

    注意

    當您使用 ( 的尾隨句點。When you use a trailing period ( . ) ,您可以防止無意中將任何預設的 DNS 尾碼加入功能變數名稱。), you prevent any default DNS suffixes from being unintentionally added to the domain name.

    此命令的輸出看起來像這樣:The output of the command looks like this:

    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
    

    您可以使用與 MX 記錄關聯的任何主機名稱或 IP 位址作為目的 SMTP 伺服器。You can use any of the host names or IP addresses that are associated with the MX records as the destination SMTP server. 喜好設定 (偏好值的較低值 = 10 與 20) 表示的是喜歡的 SMTP 伺服器。A lower value for preference (preference = 10 vs. 20) indicates a preferred SMTP server. 使用多個 MX 記錄及不同的喜好設定值,以進行負載平衡及容錯。Multiple MX records and different values of preference are used for load balancing and fault tolerance.

  4. 當您準備結束 Nslookup 會話時,請輸入 exit ,然後按 enter 鍵。When you're ready to end the Nslookup session, type exit, and then press Enter.

步驟 3:在通訊埠 25 上使用 Telnet 測試 SMTP 通訊Step 3: Use Telnet on Port 25 to test SMTP communication

在此範例中,我們會使用下列值:In this example, we're going to use the following values. 當您在伺服器上執行命令時,請以您組織的 SMTP 伺服器、網域等值取代這些值。When you run the commands on your server, replace these values with ones for your organization's SMTP server, domain, etc.

  • 目的地 SMTP 伺服器: mail1.fabrikam.comDestination SMTP server: mail1.fabrikam.com
  • 來源網域: contoso.comSource domain: contoso.com
  • 寄件者的電子郵件地址: chris@contoso.comSender's e-mail address: chris@contoso.com
  • 收件者的電子郵件地址: kate@fabrikam.comRecipient's e-mail address: kate@fabrikam.com
  • 郵件主題:來自 Contoso 的測試Message subject: Test from Contoso
  • 郵件主體:這是測試郵件Message body: This is a test message

提示

Telnet 用戶端中的命令不區分大小寫。The commands in the Telnet Client aren't case-sensitive. 在此範例中,SMTP 命令動詞會大寫,以供清晰。The SMTP command verbs in this example are capitalized for clarity. 在您連線至目的地 SMTP 伺服器後,您就無法在 Telnet 會話中使用 backspace 鍵。You can't use the backspace key in the Telnet session after you connect to the destination SMTP server. 如果您在輸入 SMTP 命令時發生錯誤,您必須按 Enter,然後重新輸入命令。If you make a mistake as you type an SMTP command, you need to press Enter, and then type the command again. 無法辨識的 SMTP 命令或語法錯誤會產生錯誤訊息,如下所示: 500 5.3.3 Unrecognized commandUnrecognized SMTP commands or syntax errors result in an error message that looks like this: 500 5.3.3 Unrecognized command.

  1. 開啟 [命令提示字元] 視窗,輸入 telnet ,然後按 enter 鍵。Open a Command Prompt window, type telnet, and then press Enter.

    此命令會開啟 Telnet 工作階段。This command opens the Telnet session.

  2. 類型 set localecho ,然後按 enter。Type set localecho, and then press Enter.

    選用 命令可讓您在輸入字元時查看字元,有些 SMTP 伺服器也可能需要這種方式。This optional command lets you view the characters as you type them, and it might be required for some SMTP servers.

  3. 類型 set logfile <filename> ,然後按 enter。Type set logfile <filename>, and then press Enter.

    選用 命令可啟用登入,並指定 Telnet 會話的記錄檔。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. 如果您指定路徑和檔案名,則路徑必須在本機電腦上,而且您可能需要在 [Windows DOS 8.3 格式] 中輸入路徑和檔案名,而不會有空格的 (短名稱) 。If you specify a path and file name, the path needs to be on the local computer, and you might need to enter the path and file name in the Windows DOS 8.3 format (short name with no spaces). 路徑必須存在,但是會自動建立記錄檔。The path needs to exist, but the log file is created automatically.

  4. 類型 OPEN mail1.fabrikam.com 25 ,然後按 enter。Type OPEN mail1.fabrikam.com 25, and then press Enter.

  5. 類型 EHLO contoso.com ,然後按 enter。Type EHLO contoso.com, and then press Enter.

  6. 類型 MAIL FROM:<chris@contoso.com> ,然後按 enter。Type MAIL FROM:<chris@contoso.com>, and then press Enter.

  7. 類型 RCPT TO:<kate@fabrikam.com> NOTIFY=success,failure ,然後按 enter。Type RCPT TO:<kate@fabrikam.com> NOTIFY=success,failure, and then press Enter.

    選用的 NOTIFY 命令會指定特定的傳遞狀態通知 (DSN) 郵件, (也稱為強制退回郵件、nondelivery 報告或 NDRs 的郵件,) 必須提供該 SMTP。The optional NOTIFY command specifies the particular delivery status notification (DSN) messages (also known as bounce messages, nondelivery reports, or NDRs) that the SMTP is required to provide. 在此範例中,您要求的是 DSN 郵件,以取得成功或失敗的郵件傳遞。In this example, you're requesting a DSN message for successful or failed message delivery.

  8. 類型 DATA ,然後按 enter。Type DATA, and then press Enter.

  9. 類型 Subject: Test from Contoso ,然後按 enter。Type Subject: Test from Contoso, and then press Enter.

  10. 再次按 Enter 鍵。Press Enter again.

    主旨 ] 欄位與郵件內文之間需要有空白行。A blank line is needed between the Subject: field and the message body.

  11. 類型 This is a test message ,然後按 enter。Type This is a test message, and then press Enter.

  12. 輸入句點 (。Type a period ( . ) ,然後按 Enter。), and then press Enter.

  13. 若要中斷與 SMTP 伺服器的連線,請輸入 QUIT ,然後按 enter。To disconnect from the SMTP server, type QUIT, and then press Enter.

  14. 若要關閉 Telnet 會話,請輸入 quit ,然後按 enter 鍵。To close the Telnet session, type quit, and then press Enter.

以下是使用上述步驟的成功會話如下所示:Here's what a successful session using the steps above looks like:

C:\Windows\System32> telnet
Microsoft Telnet> set localecho
Microsoft Telnet> set logfile c:\TelnetTest.txt
Microsoft Telnet> OPEN mail1.fabrikam.com 25
220 mail1.fabrikam.com Microsoft ESMTP MAIL Service ready at Fri, 5 Aug 2016 16:24:41 -0700
EHLO contoso.com
250-mail1.fabrikam.com Hello [172.16.0.5]
250-SIZE 37748736
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 XRDST
MAIL FROM: <chris@contoso.com>
250 2.1.0 Sender OK
RCPT TO: <kate@fabrikam.com> NOTIFY=success,failure
250 2.1.5 Recipient OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Subject: test

This is a test message.
.
250 2.6.0 <c89b4fcc-3ad1-4758-a1ab-1e820065d622@mail1.fabrikam.com> [InternalId=5111011082268, Hostname=mail1.fabrikam.com] Queued mail for delivery
QUIT
221 2.0.0 Service closing transmission channel

步驟4: Telnet 會話中的成功和錯誤訊息Step 4: Success and error messages in the Telnet Session

本節提供上一個範例中所用命令的成功和失敗回應的相關資訊。This section provides information about the success and failure responses to the commands that were used in the previous example.

注意

RFC 5321 中定義的三位數 SMTP 回應碼是相同的 SMTP 郵件伺服器,但回應中的文字描述可能稍有不同。The three-digit SMTP response codes that are defined in RFC 5321 are the same for all SMTP messaging servers, but the text descriptions in the responses might be slightly different.

SMTP 回復碼SMTP reply codes

SMTP 伺服器會以 x.x.x.x 的格式,回應具有各種數值回復碼的命令:SMTP servers respond to commands with a variety of numerical reply codes in the format of x.y.z where:

  • X 指出命令是否完好、不良或不完整。X indicates whether the command was good, bad, or incomplete.
  • Y 表示所傳送的回應類型。Y indicates the kind of response that was sent.
  • Z 提供有關命令的其他資訊Z provides additional information about the command

當開啟連線的伺服器接收到回應時,它可以判斷遠端伺服器是否接受命令,並已準備好進行下一步,或發生錯誤。When a response is received by the server that opened the connection, it can tell whether the remote server accepted the command and is ready for the next one, or if an error occurred.

第一個數位 (X) 尤為重要,因為它會指出已傳送的命令成功或失敗。The first digit (X) is particularly important to understand because it indicates the success or failure of the command that was sent. 其可能的值及其意義。Here are its possible values, and their meanings.


回復碼Reply code 意義Meaning
2. z2.y.z 已在遠端伺服器上成功完成所傳送的命令。The command that was sent was successfully completed on the remote server. 遠端伺服器已準備好進行下一個命令。The remote server is ready for the next command.
3. z3.y.z 已接受命令,但遠端伺服器需要更多資訊才能完成作業。The command was accepted but the remote server needs more information before the operation can be completed. 傳送伺服器必須使用必要資訊傳送新的命令。The sending server needs to send a new command with the needed information.
4. z4.y.z 因為可能是暫時原因,所以遠端伺服器不接受此命令。The command wasn't accepted by the remote server for a reason that might be temporary. 傳送伺服器應該稍後再次嘗試連接,以查看遠端伺服器是否可成功接受命令。The sending server should try to connect again later to see if the remote server can successfully accept the command. 傳送伺服器會繼續重試連線,直到成功完成連線, (是由 2. z 程式碼所指出) 或永久失敗 (由 5. z 程式碼) 所指示。The sending server will continue to retry the connection until either a successful connection is completed (indicated by a 2.y.z code) or fails permanently (indicated by a 5.y.z code).
暫時錯誤的範例是遠端伺服器上的低儲存空間。An example of a temporary error is low storage space on the remote server. 在有更多可用空間之後,遠端伺服器應該能夠成功接受命令。Once more space is made available, the remote server should be able to successfully accept the command.
5. z5.y.z 由於不可恢復的原因,遠端伺服器不接受此命令。The command wasn't accepted by the remote server for a reason that is isn't recoverable. 傳送伺服器不會重試連線,而且會傳送未傳遞回報給傳送郵件的使用者。The sending server won't retry the connection and will send a non-delivery report back to the user who sent the message.
無法復原之錯誤的範例是傳送至不存在之電子郵件地址的郵件。An example of an unrecoverable error is a message that's sent to an email address that doesn't exist.

上表是根據 RFC 5321 (簡易郵件傳輸通訊協定) ,section 4.2.1中提供的資訊所提供的資訊。The table above is based on information provided by RFC 5321 (Simple Mail Transfer Protocol), section 4.2.1. 其他資訊,包含 SMTP 回復碼的第二個 (Y) 和第三個 (Z) 位數的描述,也包含在 4.2.24.2.3的區段中。Additional information, including descriptions of the second (Y) and third (Z) digits of SMTP reply codes is included in this section, and in sections 4.2.2 and 4.2.3.

開啟命令OPEN command

成功回應220 mail1.fabrikam.com Microsoft ESMTP MAIL Service ready at <day-date-time>Successful response: 220 mail1.fabrikam.com Microsoft ESMTP MAIL Service ready at <day-date-time>

失敗回應Connecting to mail1.fabrikam.com...Could not open connection to the host, on port 25: Connect failedFailure response: Connecting to mail1.fabrikam.com...Could not open connection to the host, on port 25: Connect failed

可能的失敗原因Possible reasons for failure:

  • 目的 SMTP 服務無法使用。The destination SMTP service is unavailable.
  • 目的地防火牆上的限制。Restrictions on the destination firewall.
  • 來源防火牆上的限制。Restrictions on the source firewall.
  • 目的地 SMTP 伺服器的 FQDN 或 IP 位址不正確。Incorrect FQDN or IP address for the destination SMTP server.
  • 不正確的埠號碼。Incorrect port number.

EHLO 命令EHLO command

成功回應250 mail1.fabrikam.com Hello [<sourceIPaddress>]Successful response: 250 mail1.fabrikam.com Hello [<sourceIPaddress>]

失敗回應501 5.5.4 Invalid domain nameFailure response: 501 5.5.4 Invalid domain name

可能的失敗原因Possible reasons for failure:

  • 功能變數名稱中有無效字元。Invalid characters in the domain name.
  • 目的 SMTP 伺服器上的連線限制。Connection restrictions on the destination SMTP server.

注意

EHLO 是一種可擴展的簡易郵件傳輸通訊協定 (ESMTP) 在 RFC 5321 中定義的動詞。EHLO is the Extended Simple Message Transfer Protocol (ESMTP) verb that's defined in RFC 5321. ESMTP 伺服器會在初始連線期間通告其功能。ESMTP servers can advertise their capabilities during the initial connection. 這些功能包括已接受的郵件大小上限及支援的驗證方法。These capabilities include the maximum accepted message size and supported authentication methods. HELO 是 RFC 821 中定義的舊 SMTP 動詞。HELO is the older SMTP verb that is defined in RFC 821. 大部分 SMTP 郵件伺服器都支援 ESMTP 及 EHLO。Most SMTP messaging servers support ESMTP and EHLO. 如果您嘗試連線的非 Exchange 伺服器不支援 EHLO,您可以改為使用 HELO。If the non-Exchange server that you're trying to connect to doesn't support EHLO, you can use HELO instead.

MAIL FROM 命令MAIL FROM command

成功回應250 2.1.0 Sender OKSuccessful response: 250 2.1.0 Sender OK

失敗回應550 5.1.7 Invalid addressFailure response: 550 5.1.7 Invalid address

可能的失敗原因:寄件者的電子郵件地址中有語法錯誤。Possible reasons for failure: A syntax error in the sender's e-mail address.

失敗回應530 5.7.1 Client was not authenticatedFailure response: 530 5.7.1 Client was not authenticated

可能的失敗原因:目的伺服器不接受匿名郵件提交。Possible reasons for failure: The destination server doesn't accept anonymous message submissions. 如果您嘗試使用 Telnet 將郵件直接提交至沒有設定為接受匿名連線之接收連接器的信箱伺服器,就會收到此錯誤。You receive this error if you try to use Telnet to submit a message directly to a Mailbox server that doesn't have a Receive connector that's configured to accept anonymous connections.

RCPT TO 命令RCPT TO command

成功回應250 2.1.5 Recipient OKSuccessful response: 250 2.1.5 Recipient OK

失敗回應550 5.1.1 User unknownFailure response: 550 5.1.1 User unknown

可能的失敗原因:指定的收件者不存在。Possible reasons for failure: The specified recipient doesn't exist.