Skip to content

ReadableStream in email message #1500

@niquenen

Description

@niquenen

Currently with the Email Workers, an email message is defined with ForwardableEmailMessage. The message contains a property raw with the type ReadableStream to read the message. ReadableStream is a generic type and the possible types are not defined.

Screenshot 2023-12-21 at 11h56

With the get started and the following script, every data read are an Uint8Array object.

export default {
  /**
   * @param {{raw: ReadableStream}} message
   */
  async email(message, env, ctx) {
    const reader = message.raw.getReader();
    const read = await reader.read();
    if (typeof read == 'object') {
      console.log(`object type: ${read.value.constructor.name}`)
    }
    else {
      console.log(`type: ${typeof read}`)
    }
  }
}

Example of a log output from the Worker.

{
  "outcome": "ok",
  "scriptName": "email-test",
  "diagnosticsChannelEvents": [],
  "exceptions": [],
  "logs": [
    {
      "message": [
        "object type: Uint8Array"
      ],
      "level": "log",
      "timestamp": 1703151398815
    }
  ],
  "eventTimestamp": 1703151398801,
  "event": {
    "rawSize": 11889,
    "rcptTo": "[email protected]",
    "mailFrom": "[email protected]"
  },
  "id": 0
}

All types are accepted or the stream is only a ReadableStream<Uint8Array>?

Metadata

Metadata

Labels

typesRelated to @cloudflare/workers-types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions