Quickly Understanding the MIME Format of Email

The format of email is MIME. A simple MIME message consists of headers followed by a body.  For example, here’s a simple text/plain email:

From: sender@example.com
To: recipient@example.com
Subject: Example Email
Content-Type: text/plain; charset="UTF-8"

Hello,

This is a simple plain text email.

Regards,
Sender

MIME can be multipart. Here’s a text/plain email with a PDF attachment:

From: sender@example.com
To: recipient@example.com
Subject: Example Email with Attachment
Content-Type: multipart/mixed; boundary="===============1234567890"

--===============1234567890
Content-Type: text/plain; charset="UTF-8"

Hello,

This is a simple email with an attachment.

Regards,
Sender

--===============1234567890
Content-Type: application/pdf
Content-Disposition: attachment; filename="example.pdf"



--===============1234567890--

You can use Chilkat’s online tool at https://tools.chilkat.io/mimeStructure to examine the MIME structure of an email. The above multipart/mixed email has the following MIME structure:

multipart/mixed
    text/plain
    application/pdf

A more complex email is one with both plain-text and HTML alternative bodies, where the HTML includes a related image, and the email also includes an attachment. The de-facto standard way of structuring the MIME of such an email is:

multipart/mixed
    multipart/alternative
        text/plain
        multipart/related
            text/html
            image/jpeg
    application/zip

Now you have a very basic understanding of how email is composed in MIME.

Tags :