Email worker, with fetch, sending to API

I am trying to set up a catch-all email, and send all incoming emails to a worker. The work is to send the email to my API. the API will then handle the rest. Right now, I am getting rejected emails that the address dose not exist. While editing the worker, I noticed "Error: No fetch handler!"
export default {
async email(message, env, ctx) {
const response = await fetch('https://api.domain.tld', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({email:message}),
});
if (!response.ok) {}
const data = await response.json();
}
}
export default {
async email(message, env, ctx) {
const response = await fetch('https://api.domain.tld', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({email:message}),
});
if (!response.ok) {}
const data = await response.json();
}
}
3 Replies
布鲁诺 普雷托
GitHub
cloudflare-worker-emails-to-discord/index.js at master · Tyler-OBri...
Use Email Workers to forward the emails you receive to a discord webhook - Tyler-OBrien/cloudflare-worker-emails-to-discord
布鲁诺 普雷托
You cant send message like that, the body is a Stream, u need to 'process' it Refer to this Forum post : https://discord.com/channels/595317990191398933/1209897275816411136
Agung
Agung5w ago
Have you ever completed this @stevenjr1988⁣? I have a similar requirement, but my POST request is treated as GET and got 302 redirection instead. My API endpoint was used by another tool and was just fine to make the request without redirection issue.
No description

Did you find this page helpful?