MIME Types
The e-mail script we made in part 3 is good enough for most web applications,
but lacks a couple of important e-mail functions and features of modern software:
MIME handling and attachments. MIME, Multipurpose Internet Mail Extensions, is
a specification for enhancing the capabilities of standard e-mail. It allows
the user to specify and encode a variety of media types for e-mail
transmission. It also gives you more control over how the message should
be interpreted.
Using MIME types, an e-mail can contain the following:
· Text messages in the US-ASCII character set.
· Character sets other than US-ASCII.
· Non-textual media including image, audio, and video.
· Binary files.
· Messages of unlimited length.
Content-type
The content-type header field is used to specify the type and subtype of
data in the body of the message, and to specify the encoding of such data.
Possible types include text, images, audio, video, multipart, applications,
and many more.
If you don't specify a content-type, local e-mail programs will generally
assume the following type:
Content-type: text/plain; charset=us-ascii
However, since no default value for a subtype is presumed, subtypes cannot be
omitted as they have no significance alone. For example, they should be explicitly
specified as text/html and image/jpg.
Content-transfer-encoding
Many e-mail ready content types are naturally represented as 8-bit character or
binary data. However, such data cannot be transmitted over certain transport
articles, such as SMTP, which restricts e-mail messages to 7-bit US-ASCII data with
lines no longer than 1000 characters. This limitation, however, can be overcome by
using the MIME Content-transfer-encoding header field.
This header field is used to apply an encoding transformation to the message body -
which will convert the native format to a protocal-friendly one.
The Content-transfer-encoding field's value is specified
with a single type of encoding: 7bit, 8bit,
binary, quoted-printable, or
base64. The default value of a message body is 7bit
and would be encoded as such:
Content-transfer-encoding: 7bit
The quoted-printable and base64 encoding
types transform data into 7-bit format, making it safe to pass over restricted transports.
The former type doesn't work reliably with some mail tranports, leaving base64
as the sole candidate for the most reliable encoding type for transferring non-textual data.
Now we're going to explore how to send attachments (files) using our e-mail
script in Part 5 >>