FYI here only, The thing that makes an attachment in an email is a MIME header. All you are doing is dividing your text message into different parts via boundaries. You set a boundary and use it to delimit the parts of your mail message. MIME headers follow their own set of rules. Example, two \n's specify a seperation between the head and body. MIME types are diverse and give you a number of options for nesting binary data into your email. All mail messages have content-type headers just like html pages.
So a message with an attached picture would be a mixed content type. Boundaries specify where the parts are and each seperate part can also have its own content-type headers.
Obviously, a module is the fastest was to work with MIME, but if you need to go deeper the above is just a nutshell.