What is the “boundary” parameter in MIME?

Still have a question, spotted an error, or have a better explanation or a source we should cite?

A boundary is a random string that marks where one part of an email ends and another begins. If you've ever sent an email with both text and HTML versions, or added an attachment, your ESP generated a boundary string behind the scenes to keep those parts separate.

But Here's why it matters: email is fundamentally a single long text file. When you need that file to contain multiple pieces (plain text body, HTML body, an image, a PDF), something has to tell the receiving email client where each piece starts and stops. That's the boundary. It's declared in the Content-Type header and looks something like ----=_Part_12345_67890.1234567890.

The boundary string must be unique enough that it won't accidentally appear inside your actual content. If the string ----BOUNDARY shows up in your email body, and that's also your boundary marker, the email client will think that's where a new section starts. Most ESPs generate boundaries with random characters and timestamps to avoid this.

You'll almost never need to set a boundary yourself. Mailchimp, SendGrid, Postmark, and every other modern ESP handle this automatically when you upload a template or add an attachment. The only time you'd touch boundaries directly is if you're building raw MIME messages from scratch (writing your own SMTP implementation, debugging delivery issues by reading raw email source, or building a custom mail client).

And if you're curious what a boundary looks like in action, forward any email with an attachment to yourself, view the raw source (usually under "Show Original" or "View Source" in your email client), and search for "boundary=". You'll see the declared boundary string in the header, and then that same string repeated throughout the message body with -- prefixes marking each section.

Want to see the full structure of how text, HTML, and attachments fit together? Check out multipart/alternative vs multipart/mixed.

Contributors

Who worked on this answer

Every name links to their profile. Every company links to their site. Real people, real accountability.

Ask an AI · tailored to your setup

Ask Claude

I read this on the Email Almanac about MIME boundaries: "A boundary is a random string that marks where one part of an email ends and another begins. It's declared in the Content-Type header and separates text, HTML, and attachments. Most ESPs generate boundaries automatically with random characters and timestamps to avoid collisions." Help me understand how this applies to MY specific situation. I need: 1. Plain-language explanation: Why does email need boundaries at all? What happens if a boundary string accidentally appears in my content? 2. What to check in my setup: How do I know if my ESP is generating valid boundaries? Should I ever manually set a boundary string? 3. Common mistakes: What breaks when boundaries are malformed? Can incorrect boundaries cause delivery failures or spam filtering? 4. Verification steps: How do I inspect the boundary in a sent email? What tools let me view raw MIME structure? --- My details (fill in what applies): - Email platform/ESP: e.g. Mailchimp, SendGrid, custom SMTP - What I'm building: newsletter, transactional emails, custom mail client - Current challenge: what prompted this question

Edit the yellow boxes, then send to the AI of your choice.