How can someone fix this sending subject to discord webhook!

can someone help me fix export default { async email(message, env, ctx) { switch (message.from) { case "noreply@accounts.tiktok.com": const webhookUrl = 'discord.com/api/webhooks/124790903927/webhookstuff' try { const response = await fetch(webhookUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content: message.headers.get('Subject') }) }); // Handle the response if needed (e.g., check for success) } catch (error) { console.error("Error sending webhook:", error); // Optionally, handle the error gracefully (e.g., retry or notify) } break; // Important to keep this break statement default: message.setReject("Unknown address"); } } }
110 Replies
Chaika
Chaika2mo ago
subject should be directly on the email
Chaika
Chaika2mo ago
ps. if you don't want to reinvent the wheel: https://github.com/Tyler-OBrien/cloudflare-worker-emails-to-discord
GitHub
GitHub - Tyler-OBrien/cloudflare-worker-emails-to-discord: Use Emai...
Use Email Workers to forward the emails you receive to a discord webhook - Tyler-OBrien/cloudflare-worker-emails-to-discord
Alf
Alf2mo ago
do i only need to just paste the index.js code into worker?
Chaika
Chaika2mo ago
there's a setup guide in the readme
Alf
Alf2mo ago
im so confused theres so many files in this but on worker i can only have 1 then deploy, i.e wrangler publish. Create the email routes to the worker within the dashboard as you like. Note that a worker running will override any normal forwarding you have on the domain, so you have to use the option below if you want that. like what is this
Chaika
Chaika2mo ago
oh are you used to the dashboard?
Alf
Alf2mo ago
im sorry but now no
Chaika
Chaika2mo ago
workers can def have more then one file and if you're using the cli you have a minimum of 2 (index.js/index.ts and wrangler.toml)
Alf
Alf2mo ago
just bought my first domain today just so i didnt have to keep creating emails
Chaika
Chaika2mo ago
I mean, you're using the Quick Edit in the dashboard over wrangler/local dev
Alf
Alf2mo ago
and i wanted discord to be like gmail yeah think so
Chaika
Chaika2mo ago
yea that'd only work if you used local wrangler cli since it needs to package up other dependencies emails are annoying to parse if you want any of the actual content
Alf
Alf2mo ago
nah just subject but i just realised i bought the WRONG tld so i cant even use it on the platform i want i just ordered a new domani th0 i now own 3 domains because of this shi dznv.online dznv.site dznv.store @Chaika can u help me setup someone help me
Chaika
Chaika2mo ago
There's guides for getting started with wrangler/cli workers out there: https://developers.cloudflare.com/workers/get-started/guide/ https://www.youtube.com/watch?v=H7Qe96fqg1M
Cloudflare Docs
CLI | Cloudflare Workers docs
Set up and deploy your first Worker with Wrangler, the Cloudflare Developer Platform CLI.
Cloudflare Developers
YouTube
Learn Cloudflare Workers - Full Course for Beginners
Learn how to build your first Cloudflare Workers application and deploy it to Cloudflare's global network. If you don’t already have an account sign up for a free Workers account today 🔗 https://workers.cloudflare.com! 👨‍🏫 Hosted by Kristian Freeman, Cloudflare Developer Advocate 🔗 https://twitter.com/kristianf_ 🔗 Get Started guide for Cloud...
Alf
Alf2mo ago
i cant watch videos its banned in my country
Want results from more Discord servers?
Add your server