Sending attachments with MailChannels

I’m trying to send a file from an input as an email attachment using the MailChannels plugin, I am able to receive the file but it doesn’t have any name or extension. I’ve tried setting the type of the ContentItem to something specific like application/pdf but it didn’t help.

Here is the middleware.

import mailChannelsPlugin from "@cloudflare/pages-plugin-mailchannels";
import {Submission} from "@cloudflare/pages-plugin-mailchannels";
import {ContentItem} from "@cloudflare/pages-plugin-mailchannels/api";

export const onRequest = mailChannelsPlugin({
  personalizations: [
      to: [{ name: "AIUEO", email: "destination-email" }],
  from: {
    name: "AIUEO",
    email: "my-email",
  content: parseFormData,
  subject: "TEST",
  respondWith: () => {
    return new Response(
      `Thank you for submitting your enquiry. A member of the team will be in touch shortly.`

function parseFormData(s: Submission)
    const res: [ContentItem, ...ContentItem[]] = [
        {type: "text/plain", value: "nome"}];

    const file = s.formData.get("file");
        res.push({type:"multipart/form-data", value: file.toString()});
    return res;

I’d be grateful if you could help me in any way.

1 Like