Untitled
unknown
typescript
4 days ago
1.1 kB
10
No Index
in 10 days
import { EmailMessage } from 'cloudflare:email'; import { createMimeMessage } from 'mimetext'; export default { async email(message, env, ctx) { const msg = createMimeMessage(); const messageId = message.headers.get('Message-ID'); const messageSubject = message.headers.get('Subject'); console.log(messageSubject); if (!messageId) { return; } if (!messageSubject) { return; } const backendResponse = await fetch('https://localhost:8080/test', { method: 'POST', body: JSON.stringify({ userProblem: messageSubject }), }); const parsedResponse = await backendResponse.json(); msg.setHeader('In-Reply-To', messageId); msg.setSender({ name: 'Localhost Technologies', addr: 'local@host.cc' }); msg.setRecipient(message.from); msg.setSubject('Your Localhost Response!'); msg.addMessage({ contentType: 'text/plain', data: parsedResponse.reason, }); const replyMessage = new EmailMessage('local@host.cc', message.from, msg.asRaw()); await message.reply(replyMessage); await message.forward('forward@test.cc'); }, } satisfies ExportedHandler<Env>;
Editor is loading...
Leave a Comment