...where "Sent" is the full mailbox reference to my Sent folder.
This works for the most part. The mail does store successfully. However, if I go back and look at that message in a mail client, the entire thing seems to be stored as one big plaintext message. I see the entirety of the raw message body (boundary separators, part headers, attachments in base64, etc) as simple text, rather than a clean message. The main message headers are segregated correctly, but everything after that displays as raw content. Other sent messages in that folder (eg. ones that were sent with another mail client) show correctly formatted into individual parts, as expected.
Is there something I'm not doing correctly? Do I need to do something else to the $message output before saving it to the mailbox?