How do I forward a received email back to in the intended recipient? ChatGPT summarization experiment with Cloudflare email workers

I am conducting an experiment with OpenAI, which intercepts and summarizes incoming emails using Chat GPT and relays them to the intended recipient. However, I’m having trouble forwarding the modified email to its intended recipient.

I read the documentation about the Email Interface https://developers.cloudflare.com/workers/runtime-apis/email-event/#emailmessage-definition, there’s only two methods available in the EmailMessage interface, which is email.forward() and it accepts only an email address as an argument and headers. I’m not sure how to use this method to send the modified email further.

Although the summary is generated perfectly, I’m unable to relay it to the intended recipient using the below code:

export default {
  async email(message) {
    try {
      const rawEmail = await streamToArrayBuffer(message.raw, message.rawSize);
      const parser = new PostalMime();
      const parsedEmail = await parser.parse(rawEmail);
      const summaryData = await getSummaryfromOpenAi(parsedEmail.text);
      const emailWithSummary = generateEmailWithSummary(
        parsedEmail,
        summaryData
      );
      await message.forward(emailWithSummary);
      console.log("Email with summary sent");
    } catch (error) {
      console.log(error);
    } finally {
      console.log("Email processed");
    }
  },
};

I just tried running the above code, which is wrong at await message.forward, to see what happens and I get this error "TypeError: Failed to execute ‘forward’ on 'ForwardableEmailMessage': parameter 2 is not of type 'Headers'."

Can anyone help me with forwarding the modified email to its intended recipient using EmailMessage interface? Thank you in advance!