Skip to main content

Sending images over 7-bit ASCII SMTP

Short answer

SMTP carries only 7-bit ASCII, so binary data is converted using MIME. Base64 encodes 3 bytes into four printable ASCII characters, and MIME headers such as Content-Type and Content-Transfer-Encoding let the receiver decode and display the image.

SMTP is a text based protocol and uses 7 bit ASCII. How can this be used to transmit something like images? Explain.

SMTP can only carry 7-bit ASCII lines. Binary data such as images, audio, and non-English text contains bytes above 127, which SMTP cannot transmit directly. The solution is MIME (Multipurpose Internet Mail Extensions), which converts non-ASCII data to ASCII at the sender and converts it back at the receiver, without changing SMTP itself.

MIME headers added to the message

HeaderPurpose
MIME-Version: 1.0Message uses MIME
Content-TypeType of data: text/plain, image/jpeg, application/pdf, multipart/mixed
Content-Transfer-EncodingHow the data was converted to ASCII: 7bit, quoted-printable, base64
Content-Disposition / Content-IDAttachment name, inline display

Base64 encoding

Base64 takes 3 bytes (24 bits), splits them into four 6-bit groups, and maps each group (0 to 63) to a printable character (A-Z, a-z, 0-9, +, /). Padding = is used if bytes are missing.

Example: text "Man"

CharacterMan
ASCII bits010011010110000101101110

6-bit groups: 010011 | 010110 | 000101 | 101110 = 19, 22, 5, 46 = T W F u. So "Man" becomes TWFu.

The encoded size is 4/3 of the original (about 33% bigger): 300 bytes become 400 characters.

Example message with an image

From: a@x.com
To: b@y.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="XYZ"

--XYZ
Content-Type: text/plain

Photo attached.
--XYZ
Content-Type: image/jpeg
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQ... (encoded image)
--XYZ--

The receiving user agent reads the headers, decodes the base64 part back to the original bytes and shows the image. In this way the text-based, 7-bit SMTP carries images.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Networks and Security chapter 6 questions →