Last week I got access to the beta for email workers. When exploring what is possible and what not, I’m missing documentation on how to access the message body and attachments. Or alternatively the raw message (with multiple bodies for different content types and all attachments).
Is this something not documented or just not possible at all?
After some more digging, discovered there is a raw property on the message which seems to be of type ReadableStream.
Trying to put the incoming raw message on a bound R2 bucket with the put method, unfortunately results in an error: TypeError: Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream).
attachment .contents seems to be empty this is the attachment wheno try to insert and image “attachments”: [
{
“filename”: “Spiny_Babbler,_Shivapuri_Nagarjun_NP,Nepal-_IMG.sgym.17.jpg”,
“mimeType”: “image/jpeg”,
“disposition”: “inline”,
“related”: true,
“contentId”: “<ii_li8ddzh60>”,
“content”: {}
}
]
The postal-mime module API has changed, and it now includes built-in support for Cloudflare Email Workers. You can read about using it to parse emails from here: https://docs.emailengine.app/how-to-parse-emails-with-cloudflare-email-workers/
The attachment “content” is logged as an empty object because it is an Uint8Array value and you can not convert it into a JSON string.