The concept of envelope and email content(formally called “Message”) is confusing because we see many redundant stuff here. For example, there are an envelope “mail from” and a “from” header in the message itself. There are “rcpt to” in the envelope and a “To” email header. What is the difference between envelope from and from header in the message? What is the difference between envelope “rcpt to” and the “To” email header?
From the view of SMTP interaction, there is no difference between envelope and message. They are all the byte stream sent through a TCP connection. The SMTP server analyzes received byte stream and splits it into envelope and message. How does the SMTP server split the byte stream? It uses the “\r\n” as the separator. In most cases, a line is an SMTP command such as “EHLO”,”MAIL FROM”,”RCPT TO”, etc. When SMTP server receives a command, it will respond to the client with a code. If SMTP server receives a “DATA” command, it will keep receiving the following bytes (the email content)ignoring “\r\n” until it receives “\r\n”.”\r\n”(a single dot in a new line), then it realizes the email content is over and starts the subsequent relay/delivery process. The bytes after the DATA and before the dot-only line constitute the message.
A message is further split into headers and body by an empty line. There are many possible email headers such as “From:”, “To:”, “Date:”,”Subject:”,”MIME-Version:”, “Content-Type:”, “Content-Transfer-Encoding:”, etc. A special content-type is multipart content-type like:
Content-Type: multipart/related; boundary=9355a2e3ae86a0bbaab5871e39d235d
The body of a multipart message( a message with content-type:mutlipat/*) has multiple parts separated by boundary lines(the boundary line is defined also in the Content-Type: header). Note that every part of a multipart body can also have headers and body itself(separated by an empty line). Multipart message can have nested structure. Common multipart types are multipart/related, multipart/alternative, multipart/mixed,multipart/digest,multipart/report,multipart/signed,multipart/encrypted. The multipart types describe the relationship between children parts of parent part. For example, multipart/related means the parts are related with each other, which form the parent part together. You can see the multipart/related content type in a html email message that embeds images. The html and the images are related. The multipart/alternative means the parts are alternative to each other. You can provide a text version and a html version of your message, in which the text and the html are alternative to each other, the content type of the parent part should be set to multipart/alternative. The multipart/mixed types means the parts are mixed content, i.e., a text part and an attachment part. If you have attachments for your email, the text of the email and the attachments of the email must be the child parts of a parent part which has multipart/mixed content type. A multipart body can have child parts that are also multipart, which forms a complex part structure. See this discussion.
Now, you should know the difference between the To: header in the message and the envelope RCPT TO: command. There is another difference between them: To: can be followed by multiple email addresses while only one email address is allowed in the RCPT TO command(but you can send multiple RCPT TO commands in a session). There may also be a Cc: header in the message but there is no Bcc header in the message. All Cc email addresses and Bcc email addresses correspond to RCPT TO commands. There is also a possible Reply-To header in the message that is used to tell the receiver to send the reply email to, if the sender is not willing to use the From email to receive the reply. Do not confuse it with the RCPT TO command.