SMTP mail format, SMTP protocol, SMTP mime writing, SMTP sends HTML mail

Source: Internet
Author: User

Reprinted: http://blog.sina.com.cn/s/blog_759444350100vx8u.html

Mime Message format

The RFC 2822 document defines a simple ascii-encoded email mail format. However, with the development of the Internet, only simple text transmission of email mail cannot meet users' requirements, to transmit a large number of HTML, images, sounds, and attachment formats in an email, a new extended mail format-mime emerged. Due to the complexity of mime mail formats, many RFC documents define and describe the mime mail formats, such as rfc2045, rfc2046, rfc2047, rfc2049, rfc2231, rfc2387, rfc4288, and rfc4289. Therefore, the mime mail format provides us with great flexibility and brings us great difficulties in interpreting the mime-format email. The following provides a brief introduction to the mime mail format based on the original information of a specific email.

Several MIME headers starting with content-type that are commonly used and hard to understand:

Received: From jsj104 (unknown [202.204.96.147])
   By smtp14 (coremail) with smtp id wkjrdyjahalkc2lfetajag ==. 38990s2;
   Sun, 26 NOV2006 19:00:55 + 0800 (CST)
Message-ID: <000601c7114a $2fd50450 $ 9360ccca @ jsj104>
From: <ctp_41023@163.com>
To: <ctp_41023@163.com>
Subject: =? Gb2312? B? Mtizmtizxoo6wzeymzeymw =? =
Date: Sun, 26 Nov 2006 19:01:04 + 0800
Mime-type: 1.0
Content-Type: multipart/alternative;
   Boundary = "---- = _ nextpart_000_0003_01c7118d.38e01920"
X-Priority: 3
X-msmail-priority: normal
X-mailer: Microsoft outlookexpress 6.00.2900.2869
X-mimeole: produced bymicrosoft mimeole v6.00.2900.2962

This is a multi-part message in MIME format.

------ = _ Nextpart_000_0003_01c7118d.38e01920
Content-Type: text/plain;
   Charset = "gb2312"
Content-transfer-encoding: base64

Mtizmtizmtiz

------ = _ Nextpart_000_0003_01c7118d.38e01920
Content-Type: text/html;
   Charset = "gb2312"
Content-transfer-encoding: base64

Pcfet0nuwvbfiehutuwgufvcTeldicitly9xm0mvl0rurcbiVe1midqumcbucmfuc2l0aw9uYwwv
L0voij4ncjxive1mpjxirufePg0kpe1fveegahr0cc1lcxvpDj1db250zw50lvr5cgugy29uDgvu
Dd0idgv4dc9odg1soybjagfyC2v0pwdimjmxmii + dqo8tuvuqsbjb250zw50psjnU0huuwgni4w
Mc4yotawlji5otuiig5hbwu9R0vorvjbve9spg0kpfnuwuxfPjwvu1rzteu + dqo8l0hfquq + dqo8
Qk9ewsbiz0nvbg9ypsnmzmzmZmy + dqo8relwpjxgt05uihnpemu9Mj4xmjmxmjmxmjm8l0zptscsi +
Pc9esvy + pc9ct0rzp?vsfrntd4ncg =

------ = _ Nextpart_000_0003_01c7118d.38e01920 --

This email has a mail header, followed by the body of the mail, which contains a text and an HTML type. It can be noted that the line encoding "boundary =" ---- = _ nextpart_000_0003_01c7118d.38e01920 "" is used to isolate the entity parts of mime mail.

The format of the mime mail header is defined in rfc2822:

Field-name ":" [field-body] CRLF
For example:
Mime-type: 1.0
Content-Type: multipart/alternative;
Content-Type: text/plain;
Content-transfer-encoding: base64

The most common and useful MIME header starts with content-type. It is defined in rfc2046, which is roughly similar to the following content:
Content-Type: text/plain;
Content-Type: text/plain; charset = ISO-8859-1
Content-Type: text/plain; charset = US-ASCII
Content-Type: text/plain; charset = UTF-8
Content-Type: text/html;
Content-Type: text/html; charset = ISO-8859-1
Content-Type: text/CSS
Content-Type: image/GIF; name‑image004.gif
Content-Type: image/JPEG; name = "image005.jpg"
Content-Type: Message/delivery-status
Content-Type: Message/rfc822
Content-Type: Audio/X-mPEG
Content-Type: Video/MPEG-2
Content-Type: Application/MSWord
Content-Type: Application/mspowerpoint
Content-Type: Application/zip

Content-Type: multipart/mixed;   Boundary = "---- = _ part_3431_12384933.1139387792352"
Content-Type: multipart/alternative; boundary = "---- = _ part_4088_29304219.1115464258628"
Content-Type: multipart/related;   Boundary = "---- = _ part_2067_9241611.1139322711488"
Content-Type: multipart/digest;   Boundary = "---- = Next message 15543233913938263541"
Content-Type: multipart/report; report-type = delivery-status;
             Boundary = "k04g6hj9025016.1136391237/carbon.singnet.com. sg"
Content-Type: multipart/parallel

1) Content-Type: multipart/mixed
It indicates that this email contains mime entities of various formats, but does not specify the type of each object.

2) Content-Type: multipart/alternative
If the same email is sent in both text and HTML format, use Content-Type: multipart/alternative. The two mail formats actually display the same content but have different codes.

3) Content-Type: multipart/related
It is used to send HTML text and images in the same email or other similar types.

Email Subject code:

It mainly includes quoted-printable and base64 encoding. Base64 and quoted-printable are both mime (multi-purpose, multimedia email, and WWW hypertext) encoding standards used to transmit non-text data such as shapes, sounds, and faxes ).
I. base64
Base64 is the most widely used encoding on the internet today. Most e-mail software uses it as the default binary encoding, such as the commonly used outlook.
Base64 content Transfer Encoding is designed to express arbitrary sequences of eight-bit groups in a human-readable manner. The encoding and decoding algorithms are simple, but the encoding data is always 33% longer than the non-encoding data. This encoding is actually similar to the encoding method defined in rfc1421 In the PEM application.
The encoding program places the RST stream order in a 24-bit buffer, and zeros are added to the missing characters. From left to right, a 24-bit input group is composed of three eight-bit input groups in cascade mode. Then the 24 digits are truncated into four parts, each of which is 6 digits, which are translated into a separate number in the base64 alphabet. When a bit stream is encoded using base64, bit streams must be arranged in the order of highest priority. That is to say, the first byte in the stream will be the high-end bit in the first byte, while the eighth bit is the low-end byte in the first byte.
If the input data contains less than 24 characters, that is, only one or two bytes, special processing is required-enter the "=" character at the end of the data, this can block the additional information and cause confusion in encoding.
In base64 encoded data, any character other than the base64 alphabet is ignored. Invalid character sequences in base64 encoding will also be ignored, for example, "==== ".
Ii. Quoted-printable
   Quoted-printable is the same as base64 and is often used in the email system. It is usually used for 8-character encoding in a small amount of text. For example, Foxmail uses it to encode the subject and body. This encoding should be well recognized: it has a large number of '= '.
  The QP algorithm is very simple, but the encoding efficiency is very low (). It is specially designed to process 8 characters. Its algorithm is to read a single character. If the ASCII code is greater than 127, that is, if the character's 8th-bit is 1, it is encoded; otherwise, it is ignored (sometimes it is also encoded with 7 characters ).

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.