Aller au contenu
uencoder

Comment en Utiliser MIME Codage

Coder and decode MIME (Base64 with line breaks) for email attachments and multipart messages.

问题

You besoin en attach un binary fichier en un email, qui requires MIME Base64 codage avec spécifique ligne-longueur règles.

Prérequis

  • Basic understanding of email structure
  • Familiarity with Base64

Étapes

  1. 1. Understand MIME line wrapping

    MIME Base64 inserts a CRLF line break every 76 characters. This is required by RFC 2045 for email transport. Standard Base64 encoders may not add these breaks, so you must use a MIME-aware encoder.

    entrée
    binary attachment
    输出
    Base64 with CRLF every 76 chars
  2. 2. Add MIME headers

    Wrap the encoded data with Content-Type, Content-Transfer-Encoding: base64, and Content-Disposition headers. These tell the email client how to decode and present the attachment.

    entrée
    image.png
    输出
    Content-Type: image/png\nContent-Transfer-Encoding: base64\n\n<iVBOR...>
  3. 3. Decode on the receiving end

    A MIME parser reads the headers, strips the CRLF line breaks from the Base64 body, and decodes it back to the original binary. Use a MIME decoder rather than a raw Base64 decoder to handle the line breaks automatically.

    entrée
    MIME part
    输出
    original file

Résultat attendu

Un valide MIME part ce email clients peut décoder et afficher comme un attachment.

Erreurs courantes

Email client shows corrupted attachment
Ensure line breaks are CRLF (\r\n), not just LF. Some servers reject bare LF.
Decoder fails on the MIME body
Strip all whitespace and CRLF before passing to a raw Base64 decoder, or use a MIME-specific decoder.

Dépannage指引

  • If the attachment is truncated, check that your mail server does not have a line-length limit below 76.
  • Verify the Content-Transfer-Encoding header matches the actual encoding used.

Limites de sécurité

  • MIME encoding does not encrypt content. Use S/MIME or PGP for confidential attachments.

Outils associés

Termes associés

参考链接