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.