Use Telnet for SMTP/POP3/FTP/NNTP (zz)

Source: Internet
Author: User
Tags nntp response code rfc mail exchange microsoft mail mx record fully qualified domain name

Only then can we find that we can use telnet to interact with the SMTP server. The ms smtm server also provides a command line interface.
The http server can also be operated through TELNET, but there is no command line echo.

Use Telnet for SMTP // POP3 // FTP // NNTP [2]

In this series of articles, I reference the contents of Richard Stevens to the great Richard
Steven s!

[2] SMTP
Before introducing SMTP, you must first know what is MTA. The message exchange over TCP is performed by the message transmission proxy MTA.
(Message Transfer Agent. RFC 821 [Postel 1982] standardizes the SMTP protocol and specifies
On a simple TCP connection, how can two MTA communicate. RFC 822 [Crocker 1982] specifies
The format of the email message sent by RFC 821 between MTA instances.
The two MTA instances communicate with each other using nvt ascii. The customer sends a command to the server, and the server uses a digital response code.
And optional readable strings for response. The customer can only send a few commands to the server: less than 12
(In comparison, there are more than 40 FTP servers ). Let's use a simple example to illustrate the mail sending process.
Describe each command in detail.

When you need to connect to an SMTP server, you can use the following command line, where "]" indicates the end
Terminals, which can be considered as follows:
] Telnet & lt; ip address/hostname & gt; 25
If the system uses the well-known port list ing, you can use the following command line:
] Telnet & lt; IP Address/hostname & gt; SMTP

We connect to the SMTP server:
] Telnet smtp.microsoft.com SMTP
If the connection is successful, the server returns the following information:
] 220 smtp.microsoft.com Microsoft ESMTP mail service, version:
5.0.2195.6713 ready at Sun, 4 Jan 2004 08:43:53 + 0800
The customer proactively opens TCP port 25. The response code is
220 ). The server's response must start with the server's fully qualified domain name: Microsoft.com in this example
(Generally, the text following the number response is optional. The domain name is required here. The server name here is only used for display
In fact, it cannot be connected .).
To facilitate the following introduction, we use a HELP command to list the available commands of the current server,
Yes. The HELP command is not required by the server.
] Help
214-this server supports the following commands:
214 helo EHLO starttls RCPT data rset mail quit help auth turn atrn etrn
Bdat VRFY
As you can see, the server returns the response code 214 and the supported SMTP commands. The minimum SMTP command set contains 8
Commands: HELO, mail, RCPT, Data, quit, rset, VRFY, and Noop. We will see the extension later
.

Next, the customer uses the HELO command to identify himself. The parameter must be a fully qualified client host name.
Example: haohu.jforce.net.
] Helo haohu.jforce.net
250 smtp.microsoft.com Hello [10.0.0.5]
The server returns response code 250 and the customer's IP address. Many SMTP servers obtain customers' IP addresses,
Complete a DNS pointer query and compare the host name. This allows the server to register a connection with the customer based on the IP address,
Instead of based on the name that may be incorrectly typed by the user. Some servers use humorous messages to answer questions, such as "you are a scam.
Child, or "Why are you yourself ..". In this example, we can see that the Exchange Server Service
You can only print out our IP addresses through pointer query. Of course, if you are an administrator, you can modify
We will not discuss this issue here.

The MAIL command identifies the initiator of the message.
] Mail from: & lt; haohu@microsoft.com & gt;
250 2.1.0 haohu@microsoft.com... Sender OK
If the server allows the current user to use the SMTP service, it will respond to the response code 250 and the sender OK message,
For SMTP mail verification, we will not discuss it for the moment.

The next command, RCPT, identifies the receiver. If you have multiple receivers, you can send multiple RCPT commands.
] Rcpt to: & lt; haohu_cn@hotmail.com & gt;
250 2.1.5 haohu_cn@hotmail.com
Similarly, the server response code 250 indicates that the command is successful.

The content of the mail message is sent by the customer through the DATA command. The end of the message is specified by the customer. Only one
A line of periods.
] Data
354 Start mail input; end with & lt; CRLF & gt;. & lt; CRLF & gt;
Test mail

.
250 2.6.0 & lt; SMTPYjIPj8jvovSYbn00000001@smtp.microsoft.com & gt; Queued mail
The response code 354 returned by the delivery Server indicates that the email body is accepted. Enter the body of the test email.
: Test mail. As prompted by the server, & lt; CRLF & gt;. & lt; CRLF & gt; is used as the end of the email. Yes
The server returns the response code 250 after entering the email to indicate that the email is successfully entered. Simultaneously generate a message MsgID,
And include it in the mail sending queue. For more information about MsgID, see the introduction in NNTP.

The final command QUIT ends the mail exchange.
] Quit
This will disconnect the connection established using Telnet.

The RSET command aborts the current Mail transaction and resets both ends. Discard all relevant senders, receivers, or
Storage information of emails.
The VRFY command allows the customer to ask the sender to verify the recipient's address without sending an email to the recipient. Connect
It is often used manually by the system administrator when looking for mail delivery errors. We can use
If you type the VRFY command in an invalid name, the server will respond to the 550 error. If you enter a valid name
The server replies with the user name on the local host. Then we try the EXPN command to get a different answer.
The EXPN Command determines whether the user's email is forwarded and prints the forwarding address. VRFY and
EXPN Command, sometimes because of privacy, and sometimes because it is believed to be a security vulnerability.
The NOOP command does nothing except to force the server to respond to an OK response code (200.
The EXPN extended email table, similar to VRFY, is usually used by the system administrator.

The TURN command enables the customer to exchange roles with the server, so the opposite can be achieved without removing the TCP connection and establishing a new connection.
Send emails to the specified region. The other three commands that are rarely implemented (SEND, SOML, and SAML) Replace the MAIL command.
These three commands allow direct mail to be sent to the client terminal (if registered) or to the recipient's mailbox.

An email consists of three parts:
1) The envelope (envelope) is delivered by MTA. In our example, the envelope is specified by two SMTP commands.
:
] MAIL From: & lt; haohu_cn@hotmail.com. & gt;
] RCPT To: & lt; mylover@anywhere.net & gt;
RFC 821 specifies the content of the envelope and its interpretation, as well as the protocol used to exchange mail on a TCP connection.
2) the header is used by the user agent. Let's take a look at the mail header information sent before:
] Microsoft Mail Internet Headers Version 2.0
Received: from ([10.0.0.5]) by smtp.microsoft.com with Microsoft
SMTPSVC (5.0.2195.6713 );
Sun, 4 Jan 2004 09:03:55 + 0800
From: haohu@microsoft.com
Bcc:
Return-Path: haohu@microsoft.com
Message-ID: & lt; SMTPYjIPj8jvovSYbn00000001@smtp.microsoft.com & gt;
X-OriginalArrivalTime: 04 Jan 2004 01:04:12. 0441 (UTC)
FILETIME = [AA6B1890: 01C3D25E] Date: 4 Jan 2004 09:04:12 + 0800
In our example, we can see six header fields: sorted ed, From, Bcc,
Return-Path (Reply-To), Message-Id, and X-OriginalArrivalTime. No email header entered
The example is based on Exchang Server 2000. According to the different sending methods, the mail header
The fields are different. Each header field contains a name followed by a colon followed by the field value. RFC
822 indicates the format of the header field (the header field starting with X-is a user-defined field, and the others are
Defined in RFC 822 ). A long header field, such as the sorted ed in the example, is folded in several rows, leading to spaces for extra rows.
. The example here is to start a row again at Sun.
3) The body is the content sent to and received by the user. RFC 822 specifies the body as NVT
ASCII lines. When you use the DATA command to send a message, the first line is sent first, followed by an empty line, followed by the body. Use
Each row sent by the DATA command must be smaller than 1000 bytes. The user receives the part that we specify as the body, and adds some
First field and upload the result to MTA. Add some header fields to MTA, add an envelope, and send the result to another
MTA. Content is usually used to describe the combination of header and body. The content is sent by the customer using the DATA command
.

As email is becoming more and more widely used, the original commands and codes are not suitable for use. Therefore, RFC performs
. You can use the extended MTA (for example, the email server we use as an example)
Execute EHLO to display the expanded command list.
] Ehlo
250-smtp.microsoft.com Hello [10.0.0.5]
250-TURN
250-ATRN
December 250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS = LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH = LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
As you can see, many extended commands are listed in the 250 response to the EHLO command. Some of the original RFC 821
Specifications, but they are optional commands. ESMTP servers describe the optional RFC supported in addition to new commands
The 821 command. The SIZE keyword supported by this server is in RFC 1427 [Klensin, Freed, and Moore 1993]
. It allows the customer to specify the packet size in bytes in the mail from command line, so that the server
You can verify whether the message of this length is received before the customer starts sending the message. Add the original
Because, with the support for non-ASCII code (such as audio and audio) content, the length of Internet Mail packets
Increasing.
The keyword 8BITMIME is from RFC 1426 [Klensin, 1993a]. It allows the customer to add the keyword BODY
In the mail from command, specify whether the body contains nvt ascii characters (default) or 8 bit data. Division
The client does not receive the 8BITMIME keyword sent by the server to respond to the EHLO command; otherwise, the client is prohibited from sending any non-NVT
ASCII characters (when we talk about MIME in this section, we will see that MIME does not require 8-bit transfer ). Any
All the keywords starting with "X" refer to the local SMTP extension.
RFC 1522 [Moore 1993] specifies how to send non-ASCII characters in the header of an RFC 822 message.
Method. This is mainly used to allow other characters in the sender name, receiver name, and topic.
The header field can contain a coded word ). They have the following formats:
=? Charset? Encoding? Encoded-text? =
Charset is a character set specification. Valid values are two strings, us-ascii and iso-8859-x, where x is
A single number, such as the number "1" in the iso-8859-1 ". Encoding is a single character used to specify encoding
Method. Two values are supported. We can see that this content is not included in the decoded information in many emails.
1) Q encoding refers to quoted-printable, which is used for the Latin character set.
Most characters are sent as nvt ascii (of course, the highest bit is set to 0. Any character to be sent
If the 8-bit value is set to 1, it is sent as three characters: The 1st characters are "=", followed by two hexadecimal numbers. For example,
Character & #233; (its 8-bit binary value is 0xe9) is sent as three characters: = E9. A space is usually used as an underscore or
Three characters = 20. This encoding aims to include a few ASCII characters in some texts.
Special characters.
2) B indicates the 64-based encoding. The three consecutive bytes (24bit) in the text are encoded into four 6 bits.
Value. The following table lists the 64 nvt ascii characters that indicate all possible 6-bit values. When the number of codes to be encoded is not
When it is a multiple of 3, the equal sign "=" is used as a fill character. The Base64 code table is listed below:
_____________________________________
6Bit 0 1 2 3 4 5 6 7
ASCII A B C D E F G H
-------------------------------------
6Bit 8 9 a B c d e f
ASCII I J K L M N O P
-------------------------------------
6bit 10 11 12 13 14 15 16 17
Ascii q r s t u v w x
-------------------------------------
6bit 18 19 1A 1B 1C 1D 1E 1f
ASCII y z A B C D E F
-------------------------------------
6bit 20 21 22 23 24 25 26 27
ASCII g h I j k l m n
-------------------------------------
6bit 28 2a 2B 2C 2D 2E 2f
ASCII o p q r s t U V
-------------------------------------
6bit 30 31 32 33 34 35 36 37
ASCII w x y z 0 1 2 3
-------------------------------------
6bit 38 39 3A 3B 3C 3D 3E 3f
ASCII 4 5 6 7 8 9 +/
-------------------------------------
RFC 822 specifies that the body is an nvt ASCII text line with no structure. RFC 1521 [Borenstein and freed
1993] define the extension to allow the structure to be placed into the body. This is called MIME, which is a universal Internet Mail Extension.
MIME does not require any extensions. We have described this section (expanded SMTP or non-ASCII titles ).
MIME is added with some new headers that inform the recipient of the body structure (same as RFC 822 ). The body can still be
Use the nvt ascii code instead of the content of the email. Although some of the extensions we mentioned earlier may
MIME is combined to produce good results-the expanded smtp size command, because the MIME message can become very long, and
Non-ASCII titles-these extensions are not required by MIME. To exchange MIME messages with the other Party
Both parties must have a user agent that understands MIME. No changes are required in any MTA.
MIME defines the five new title fields as follows:
Mime-Version:
Content-Type:
Content-Transfer-Encoding:
Content-ID:
Content-Description:
Text is one of the seven defined content types of MIME. The following table summarizes 16 differences defined in RFC 1521.
Content type and child type. Many parameters are specified for the specific content type and child type.

Content type subtype description
Text plain unformatted text
Richtext text in simple format, such as bold, italic, or underline
Simplified and improved enriched richtext
Multipart mixed multiple body parts for serial Processing
Parallel multiple body parts for parallel Processing
Digest abstract of an email
Altenative has multiple body parts with the same semantic content
Message rfc822 is another RFC 822 email message.
Partial content is a piece of mail message
External-body content is a pointer to the actual message
Application octet-stream arbitrary binary data
Postscript: a PostScript Program
Image jpeg ISO 10918 format
Gif CompuServe format
Audio basic is encoded in 8-bit ISDN μ-Law format
Video mpeg ISO 11172 format

The content type and the Transfer Encoding used for the content are independent of each other. The former is indicated by the Content-Type field in the header.
The latter is specified by the Content-Transfer-Encoding header. Five different types
Encoding format.
1) 7bit, which is the default nvt ascii;
2) quoted-printable, we can see in the previous example that there is a non-ASCII header. Only
It is very useful when the 8bit of a small part is set to 1;
3) base64, as shown in the preceding encoding table;
4) 8 bits, including character lines, some of which are non-ASCII characters and the 8bit value is set to 1;
5) binary encoding, which does not need to contain 8-bit data of multiple rows.
For RFC 821 MTA, only the first three of the preceding five encoding formats are valid. Because these three types of products only contain
The body of the nvt ascii character. 8-bit encoding is allowed for SMTP extension supported by 8 bitmime. Despite content
The types and codes are independent. RFC 1521 recommends quoted-printable for text with non-ASCII data, while
Image, audio, video, and octet-stream application Use base 64. This allows
821 of MTA maintain maximum interoperability. In addition, the multipart and message content types must be 7-bit encoded.
For details and examples of MIME, see RFC 1521 and [Rose1993].

One type of resource record in DNS is mail exchange record, which is called MX record. You can use MX record to direct
Send emails to hosts connected to the Internet. RFC 974 [Partridge 1986] describes the location of the mta mx record
. Through the DNS server, MTA can find the MX records of the target host. When there are multiple MX records, use
MX records with low-priority values.
Due to the diversity of systems, the interaction between MTA and DNS varies with different implementations. RFC 974 indicates that the MTA is required.
The MX record must be required first. If no record exists, try to submit the record to the target host (that is
And IP addresses ). The MTA must also process the CNAME record (canonical name) in the DNS ). Another use of MX records
Is to provide another email receiver when the target host fails. This function can also be used in the use of ADSL
. Due to the uncertainty of the IP address caused by ADSL, we often need backup email services.
. At this time, you can also add an MX record to the DNS server that provides dynamic domain name resolution, so that it is sent to this dynamic
The email on the server with the domain name takes precedence over the ADSL connection. If the connection fails, the server can connect to other email servers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.