Mayne
Mayne
CDCloudflare Developers
Created by Mayne on 12/24/2024 in #workers-help
Issue: Email Reply Chain Handling Failure
Issue: Email Reply Chain Handling Failure Description When using the Workers Email service to handle email communications, the service fails to process replies to auto-generated responses. While the initial auto-reply functionality works as expected, any subsequent replies from users to these auto-generated emails result in an internal error. The worker throws an internal error when processing reply emails. The error occurs at Object.email (index.js:13934:5) with an "internal error" message. The specific error details are not accessible. Reproduction Steps 1. Configure a Workers Email handler (e.g., [email protected]) 2. Send an initial email to [email protected] 3. Receive an auto-reply from the Worker 4. Reply to the auto-reply email 5. Worker fails to process the reply with an internal error Code Example
import { EmailMessage } from 'cloudflare:email';
import { createMimeMessage } from 'mimetext';

export default {
async email(message: any, env: Env, ctx: ExecutionContext) {
const msg = createMimeMessage();
msg.setHeader('In-Reply-To', message.headers.get('Message-ID'));
msg.setSender({ name: 'Thank you for your contact', addr: message.to });
msg.setRecipient(message.from);
msg.setSubject('Email Routing Auto-reply');
msg.addMessage({
contentType: 'text/plain',
data: `We got your message, your ticket number is ${self.crypto.randomUUID()}`,
});
console.log({
sender: message.to,
recipient: message.from,
});

const replyMessage = new EmailMessage(message.to, message.from, msg.asRaw());

await message.reply(replyMessage);
},
};
import { EmailMessage } from 'cloudflare:email';
import { createMimeMessage } from 'mimetext';

export default {
async email(message: any, env: Env, ctx: ExecutionContext) {
const msg = createMimeMessage();
msg.setHeader('In-Reply-To', message.headers.get('Message-ID'));
msg.setSender({ name: 'Thank you for your contact', addr: message.to });
msg.setRecipient(message.from);
msg.setSubject('Email Routing Auto-reply');
msg.addMessage({
contentType: 'text/plain',
data: `We got your message, your ticket number is ${self.crypto.randomUUID()}`,
});
console.log({
sender: message.to,
recipient: message.from,
});

const replyMessage = new EmailMessage(message.to, message.from, msg.asRaw());

await message.reply(replyMessage);
},
};
5 replies