I realized that I could use Telnet to interact with the SMTP server. The SMTM server for MS also provides an interface for command-line interaction.
HTTP server is also able to use Telnet to operate, but there is no command line echo.
Using Telnet for SMTP//POP3//FTP//NNTP [2]
In this series of articles, I quote the content of Richard Stevens to the great Richard
Stevens salute.
[2] SMTP
Before you introduce SMTP, you need to know what the MTA is. Mail exchange with TCP is sent by the messaging agent MTA
(Message Transfer Agent) completed. RFC 821[postel 1982] regulates the SMTP protocol, specifying the
On a simple TCP connection, how two MTAs communicate. RFC 822[crocker 1982] specified in both
The format of e-mail messages sent between MTAs in RFC 821.
Two MTAs communicate with NVT ASCII. The client sends a command to the server with a digital answer code
and an optional human-readable string to respond to. Customers can only send a few commands to the server: less than 12 basic
(In comparison, there are more than 40 ftp). We use simple examples to illustrate the process of sending mail, not
Describe each command in detail.
When you need to connect to an SMTP server, you can use the following command line, which uses "]" to indicate the end
The end of the display, if there is no special description, can be considered that:
] Telnet <ip address/hostname> 25
If the system uses well-known port list mappings, you can use the following command line:
] Telnet <ip address/hostname> Smtp
We connect to the SMTP server:
] Telnet smtp.microsoft.com SMTP
If the connection succeeds, the server returns the following information:
] smtp.microsoft.com Microsoft ESMTP MAIL Service, Version:
5.0.2195.6713 Ready at Sun, 4 2004 08:43:53 +0800
Client actively opens TCP port 25. When returned, the customer waits for a greeting message from the server (the answer code is
220). The server's answer must start with the fully qualified domain name of the server: in this case microsoft.com
(Usually, the text following the answer to the number is optional.) This requires a domain name. The server name here is used only as an example
example, is actually unable to connect. )。
To facilitate the introduction below, we use a help command to list the available commands for the current server, but
Note that 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
BDAT VRFY
As you can see, the server returned the response code 214 and the supported SMTP commands. The smallest SMTP command set contains 8
A command: Helo,mail,rcpt,data,quit,rset,vrfy,noop. Later we will also see the extension
SMTP command.
Next, customers use the HELO command to identify themselves. The parameter must be a fully qualified client host name, which is also
Use an example: Haohu.jforce.net.
] Helo haohu.jforce.net
Smtp.microsoft.com Hello [10.0.0.5]
The server returns the response code 250, as well as the client's IP address. Many SMTP servers get the client's IP address,
Completes a DNS pointer query and compares the host name. This allows the server to register the client's connection based on the IP address,
Instead of a name that the user might incorrectly type. Some servers will respond with a humorous message, such as "You are a cheat
Son ", or" Why do you call yourself ... "? In this example, we see that this Exchange Server service
Through the pointer query only print out our IP address, of course, if you are the administrator you can make changes, but
We are not discussing this issue here.
The Mail command identifies the originator of the message.
] Mail from:<haohu@microsoft.com>
2.1.0 Haohu@microsoft.com....sender OK
If the server allows the current user to use the SMTP service, it will respond to response code 250 and sender OK messages,
As for the SMTP letter verification, we do not discuss it for the time being.
Next command, RCPT, identifies the receiving party. If you have more than one receiver, you can send multiple RCPT commands.
] RCPT to:<haohu_cn@hotmail.com>
Haohu_cn@hotmail.com 2.1.5
Similarly, the server responds with the response code 250 that represents the command success.
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, is only a
A line with a period.
] Data
354 Start mail input; End With < crlf>. < Crlf>
Test mail
.
2.6.0 < Smtpyjipj8jvovsybn00000001@smtp.microsoft.com> Queued Mail for
The delivery server returns response code 354 to begin accepting the message body. We enter the message body of the test
: Test mail. As prompted by the server, this is actually a < crlf>. < Crlf> as the end of the message. Can
To see that the server returns a response code of 250 after the end of the message input is successful. At the same time generate a message msgid,
and put it in the mail delivery queue. For MsgId, you can look at the introduction in NNTP.
The final command quit, ending the exchange of messages.
]quit
This will disconnect the connection that was established using Telnet.
The RSet command abnormally aborts the current mail transaction and resets both ends. Throw away all relevant senders, receivers, or
The storage information for the message.
The Vrfy command allows the customer to ask the sender to verify the recipient's address without sending a message to the receiver. Flux
It is often used by the system administrator to find mail delivery errors manually. If the server supports it, we can use
An invalid name type the Vrfy command, and the server responds to 550 errors. If you type a valid name, suit
The service is answered 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 message is forwarded and prints out the forwarded address. Many sites prohibit vrfy and
expn commands, sometimes because of privacy, sometimes because it is believed to be a security breach.
The NoOp command does nothing except force the server to respond to an OK Answer code (200).
The EXPN expanded mailing table, similar to Vrfy, is typically used by system administrators.
The turn command enables customers and servers to exchange roles, eliminating the need to remove TCP connections and establishing new connections to reverse
Direction to send the message. There are three other commands that are rarely implemented (SEND, SOML, and SAML) to replace mail commands.
These three commands allow the message to be sent directly to the client terminal (if registered) or to the recipient's mailbox.
E-mail is made up of three parts:
1) The envelope (envelope) is used by the MTA for delivery. In our example, envelopes are indicated by two SMTP commands
:
] MAIL from: <haohu_cn@hotmail.com.>
] RCPT to: <mylover@anywhere.net>
RFC 821 indicates the contents of the envelope and its interpretation, as well as the protocol for exchanging messages on a TCP connection.
2 The first is used by the user agent. Let's take a look at the message header message that was 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, 2004 09:03:55 +0800
From:haohu@microsoft.com
Bcc:
Return-path:haohu@microsoft.com
Message-id: < Smtpyjipj8jvovsybn00000001@smtp.microsoft.com>
x-originalarrivaltime:04 01:04:12.0441 (UTC)
FILETIME=[AA6B1890:01C3D25E] Date:4 2004 09:04:12 +0800
In our example, we can see 6 header fields: Received, from, BCC,
Return-path (reply-to), Message-id, X-originalarrivaltime. This is no input headers
Sent directly, the example is based on Exchang Server 2000. According to different ways of sending mail, headers
The fields are not the same. Each header field contains a name, followed by a colon, followed by a field value. Rfc
822 indicates the interpretation of the format of the header field (the first X-Start field is a user-defined field, and the other is the
RFC 822 defined). The long header field, such as the received in the example, is folded in a few lines and the extra lines are in space
Beginning. The example here is to start a new line at Sun.
3 the text (body) is the content that sends the user to receive the user message. RFC 822 Specifies that the body is NVT
The ASCII text line. When sent with the data command, the header is sent first, followed by a blank line, and then the body. Use
Each row sent by the data command must be less than 1000 bytes. The user receives the part that we specify as the body, plus some
The header field and upload the result to the MTA. The MTA plus some header fields, plus envelopes, and sends the results to another
An MTA. Content is often used to describe the combination of the header and the body. The content is sent by the customer with the data command
Of
As the use of e-mail is more and more extensive, the original command, coding, etc. is not enough to use. So the RFC does it
The expansion. For an MTA that supports extensions (such as the mail server we use for example), you can
Make EHLO to display a list of its expanded commands.
] Ehlo
250-smtp.microsoft.com Hello [10.0.0.5]
250-turn
250-atrn
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
OK
As you can see, many of the extended commands are listed in the 250 response to the EHLO command. There are some from the original RFC 821
Specifications, but they are optional commands. ESMTP server Description What optional RFCs are supported in addition to the new commands
821 command. The SIZE keyword supported by this server is in RFC 1427[klensin, freed and Moore 1993]
is defined in. It allows the customer to specify the size of the message in bytes in the Mail from command line, so that the server
You can verify that the message is received by the client before it starts sending the message. Increase the original of this command
Because, with the support for non-ASCII code (such as images, audio, etc.), the length of the Internet mail message
is growing.
Keyword 8BITMIME from RFC 1426[klensin etc, 1993a]. It allows customers to add the keyword body
To the mail from command, specify whether the body contains NVT ASCII characters (the default) or 8 bit data. Except
Non-customer receives the server to answer the EHLO command to send the 8BITMIME keyword, otherwise prohibit the customer to send any non nvt
ASCII characters (when we talk about MIME in this section, we will see that MIME does not require 8 bit transfer). Anything to
The keyword at the beginning of x refers to the local SMTP extension.
RFC 1522[moore 1993] indicates a party that sends non-ASCII characters in the RFC 822 message header
Method. The primary purpose of this is to allow other characters to be used in the sender name, receiver name, and subject.
The header field can contain a coded word (coded word). They have the following format:
=?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
A single number, such as the number "1" in iso-8859-1. Encoding is a single character used to specify the encoding
method to support two values. We can include this content in a lot of emails that don't decode information.
1 Q encoding means printable in quotation marks (quoted-printable), and is intended for use in Latin character sets.
Most characters are sent as Nvt ASCII (of course, the highest-order bit-0). Any character to be sent, if its first
8 bit 1 is sent as 3 characters: The 1th is the character is "=" followed by two hexadecimal digits. For example
The character & #233 (its binary 8bit value is 0XE9) is sent as three characters: =e9. Spaces are usually underlined or
Three characters = 20 send. The purpose of this encoding is that some text, in addition to most ASCII characters, has several
A special character.
2 B means the code with a base of 64. 3 consecutive bytes (24bit) in the text are encoded into 4 6 bit
Value. The 64 NVT ASCII characters used to represent all possible 6bit values are shown in the following table. When the number to encode is not
is a multiple of 3, the equal sign "=" is used as a fill. The following is a list of the code tables for BASE64:
_____________________________________
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 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 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-3a 3b 3c 3d 3e 3f
ASCII 4 5 6 7 8 9 +/
-------------------------------------
RFC 822 Specifies that the body is NVT ASCII text line with no structure. RFC 1521[borenstein and freed
1993] The extension is defined as allowing the structure to be placed into the body. This is called MIME, the Universal Internet Mail extension.
MIME does not require any extensions, as we explained earlier in this section (extended SMTP or non-ASCII headers).
MIME adds a new title that informs the recipient's body structure (consistent with RFC 822). Body can still
Use NVT ASCII code to send, regardless of the content of the message. Although some of the extensions we have described earlier May and
The MIME fits together to produce a good effect-the extended SMTP size command because the MIME message can become very long, and
Non-ASCII headers-these extensions are not required by MIME. All that is needed to exchange MIME messages with the other party
Is that both sides should have a user agent that can understand mime. There is no need to make any changes in any of the MTAs.
The MIME definition of these 5 new title fields is as follows:
Mime-version:
Content-type:
Content-transfer-encoding:
Content-id:
Content-description:
Text is one of 7 defined content types for MIME. The following table summarizes the 16 differences defined in RFC 1521
's content type and subtype. There are a number of parameters specified for the specific content type and subtype.
Content Type subtype Description
Text Plain unformatted Text
RichText simple format text, such as bold, italic, or underline
Simplification and improvement of enriched RichText
Multipart mixed multiple body parts, serial processing
Parallel multiple body parts, which can be processed in parallel
Digest a summary of an e-mail message
Altenative multiple body parts with the same semantic content
Message rfc822 content is another RFC 822 mail packet
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
Graphic Interchange format for GIF CompuServe
Audio Basic is encoded with a 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 content-type by the header field
Ming, the latter is indicated by the first field content-transfer-encoding. In RFC 1521, you define 5 different
Encoding format.
1) 7bit, is the default NVT ASCII;
2 Quoted-printable, we see a non-ASCII header in the previous example. When the character is only
A very small part of the 8bit 1 o'clock is very useful;
3) Base64, as shown in the coding table above;
4 8bit, containing character rows, some of which are non-ASCII characters and 8bit to 1;
5) binary encoding without the need to contain multiple lines of 8bit data.
For RFC 821 MTA, only the first 3 of the above 5 encoding formats are valid. Because these 3 kinds of produce only contain
The body of the NVT ASCII character. Use of extended SMTP with 8BITMIME support allows 8bit encoding. Although the content
Type and encoding are independent, RFC 1521 recommends text using Quoted-printable without ASCII data, and
Image, audio, video, and Octet-stream application use Base 64. This allows for compliance with RFC
821 of the MTA maintains maximum interoperability. Also, the multipart and message content types must be encoded in 7bit.
For details and examples of MIME, see RFC 1521 and [Rose1993].
One type of resource record in DNS is a mail exchange record, called an MX record. You can use MX records to not be straight
A host that connects to the Internet sends mail. RFC 974[partridge 1986] Describes the place of the MTA to MX records
Acting With a DNS server, the MTA can discover the MX record of the destination host and, in the case of multiple MX records, use the
An MX record with a low priority series value.
Because of the multiplicity of systems, the interaction between MTA and DNS varies with different implementations. RFC 974 Specifies that the MTA must
MX records must be required first, and if not, attempt to submit to the destination host (that is, the memory of the host to DNS
Recording and IP address). The MTA must also handle the CNAME record (the name of the specification) in DNS. Another use of MX records
is to provide another message sink when the destination host fails. This feature can also be implemented in the use of ADSL
In Dynamic DNS resolution. Because of the uncertainty of IP address caused by ADSL, we often need back-up mail service.
Manager You can also add an MX record to a DNS server that provides dynamic domain name resolution, which enables you to send this dynamic
Domain name of the server's mail priority attempt ADSL connection, failed to connect to other mail server.