You can also look at how Marcus de Geus did that in RexxMail. IIRC, attachments have to be base64-encoded, but I don't know how they are appended to the message text.
It looks like a lot of work, so using PMMail or one of the older Mozilla add-ons might be easier.