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 "[email protected]": 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
Chaika5mo ago
subject should be directly on the email
Chaika
Chaika5mo 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
AlfOP5mo ago
do i only need to just paste the index.js code into worker?
Chaika
Chaika5mo ago
there's a setup guide in the readme
Alf
AlfOP5mo 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
Chaika5mo ago
oh are you used to the dashboard?
Alf
AlfOP5mo ago
im sorry but now no
Chaika
Chaika5mo 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
AlfOP5mo ago
just bought my first domain today just so i didnt have to keep creating emails
Chaika
Chaika5mo ago
I mean, you're using the Quick Edit in the dashboard over wrangler/local dev
Alf
AlfOP5mo ago
and i wanted discord to be like gmail yeah think so
Chaika
Chaika5mo 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
AlfOP5mo 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
Chaika5mo 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
AlfOP5mo ago
i cant watch videos its banned in my country
Erisa
Erisa5mo ago
the first link is the text form you can follow that instead
Alf
AlfOP5mo ago
@Chaika @Erisa bro it keeps telling me to install nom where tf is npm im actually turning mad from this
gwapes
gwapes5mo ago
npm stands for node package manager, it comes when you install node. Node is a runtime for JavaScript.
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
bro tf is this shi
Alf
AlfOP5mo ago
GitHub
GitHub - xinLaboratory/cloudflare-worker-emails-webhook: Use Email ...
Use Email Workers to forward the emails you receive to a webhook - xinLaboratory/cloudflare-worker-emails-webhook
Alf
AlfOP5mo ago
@Erisa bro @Erisa @Chaika
John Spurlock
John Spurlock5mo ago
?pings
Flare
Flare5mo ago
Please do not ping community members for non-moderation reasons. Doing so will not solve your issue faster and will make people less likely to want to help you.
Alf
AlfOP5mo ago
sorry mate just people are begging me to finish
gwapes
gwapes5mo ago
Then you should follow some guide on how to get started. But, if you make a worker, then go to edit code then go to wrangler it’ll say to develop with wrangler. From there you can clone that project and then just paste that code you have
Alf
AlfOP5mo ago
bro im doing this on vscode on cloudflare website they aint got a terminal
gwapes
gwapes5mo ago
There will be a cmd you can paste
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
bro its broken asf
gwapes
gwapes5mo ago
You can just do wrangler init —from-dash <worker-name>
Alf
AlfOP5mo ago
where tf is that bro pls can i just screenshare u
gwapes
gwapes5mo ago
On the Cloudflare dashboard Where you make a worker
Alf
AlfOP5mo ago
bro lemme screenshare i beg 🙏
gwapes
gwapes5mo ago
No, it’s not rocket science
Alf
AlfOP5mo ago
it fricking is
gwapes
gwapes5mo ago
I gave you the things you need
Alf
AlfOP5mo ago
bro im confsued asf
gwapes
gwapes5mo ago
Go to the dashboard, make a new worker
Alf
AlfOP5mo ago
ok bro i will pay u to goto dms and lemme screenshare
gwapes
gwapes5mo ago
No, it’s not hard, it’s really, really not hard I’m a bit special as it is and even I can do it
Alf
AlfOP5mo ago
maybe im more special and need to screenshare to someone u dont gotta speak
gwapes
gwapes5mo ago
Can you not go to the dashboard?
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
click this button yes?
gwapes
gwapes5mo ago
Yes
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
what todo here just press deploy?
gwapes
gwapes5mo ago
There’s a big fat deploy button Yes
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
where now @gwapes
gwapes
gwapes5mo ago
Try the wrangler cli
Alf
AlfOP5mo ago
where now
Alf
AlfOP5mo ago
No description
gwapes
gwapes5mo ago
Ok nvm go back, and click “edit code”
Alf
AlfOP5mo ago
no i installed wrangler do i delete
gwapes
gwapes5mo ago
Go here and click edit code
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
ok @gwapes now what
gwapes
gwapes5mo ago
Bro please stop pinging me every time
Alf
AlfOP5mo ago
oh sorry
gwapes
gwapes5mo ago
They also changed the layout… Ok wrangler init —from-dash helloworld-webhook — it’s two -‘s
Alf
AlfOP5mo ago
alright where do i put that
gwapes
gwapes5mo ago
In vscode
Alf
AlfOP5mo ago
in my computer terminal?
gwapes
gwapes5mo ago
Terminal
Alf
AlfOP5mo ago
okty
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
not really
gwapes
gwapes5mo ago
Put npx before wrangler
Alf
AlfOP5mo ago
No description
gwapes
gwapes5mo ago
Errrrr, put "’s around helloworld-webhook ig? Or tbh at this rate clone the repo and put the specific worker name in the wrangler.toml
Alf
AlfOP5mo ago
No description
gwapes
gwapes5mo ago
Do this instead
Alf
AlfOP5mo ago
name = "helloworld-webhook" main = "worker.js" compatibility_date = "2022-01-11" [vars] The necessary secrets are: - DISCORD_WEBHOOK_URL You can set this to forward to an address as well - FORWARD_TO_ADDRESS @gwapes what this be
gwapes
gwapes5mo ago
I mean, idk, since i don’t know the project. But if you wanna set a secret, then you should use npx wrangler secret put <name> Then a prompt will come up asking you to put the secret
Alf
AlfOP5mo ago
bro i typed all that out how to set secret without npx
gwapes
gwapes5mo ago
Could just paste it straight into the code lol
Alf
AlfOP5mo ago
my ctrl y isnt working
Isaac McFadyen
Isaac McFadyen5mo ago
You used an emdash instead of a regular dash which is - You should be using two regular dashes like --
gwapes
gwapes5mo ago
Thought so, I knew something looked funky. iOS seems to have funny -‘s
Isaac McFadyen
Isaac McFadyen5mo ago
Yeah it's Apple's "smart dashes" and "smart quotes", they sometimes mess things up.
Alf
AlfOP5mo ago
npx wrangler init --from-dash "helloworld-webhook"
Isaac McFadyen
Isaac McFadyen5mo ago
Yes, like that.
Alf
AlfOP5mo ago
like this
gwapes
gwapes5mo ago
Not that smart then But you don’t need that if you cloned the repo
Alf
AlfOP5mo ago
it aint working cloned
gwapes
gwapes5mo ago
You can just put the worker name in the .toml file and then do wrangler deploy which will do it
Alf
AlfOP5mo ago
No description
gwapes
gwapes5mo ago
I also have 0 idea on how the email routing works
Alf
AlfOP5mo ago
alright what now
Isaac McFadyen
Isaac McFadyen5mo ago
What is "not working"? Are you getting an error?
Alf
AlfOP5mo ago
says require aint defined
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
also what stops someone else accessing my worker through terminal?
Isaac McFadyen
Isaac McFadyen5mo ago
You need to change your imports. Change the top two lines:
import PostalMime from "postal-mime";
import {convert} from "html-to-text";
import PostalMime from "postal-mime";
import {convert} from "html-to-text";
Alf
AlfOP5mo ago
i didnt need any authorization
Isaac McFadyen
Isaac McFadyen5mo ago
You don't have a fetch handler so they can't do that.
gwapes
gwapes5mo ago
I mean if you have a shared computer then, well, don’t let them on it. Otherwise nothing
Isaac McFadyen
Isaac McFadyen5mo ago
They can definitely deploy if they have the code + your authentication on your computer, but they can't send a request to the deployed Worker.
Alf
AlfOP5mo ago
bro
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
what tf is this why it still say require
Isaac McFadyen
Isaac McFadyen5mo ago
Change: const parser = new PostalMime.default(); to: const parser = new PostalMime();
Alf
AlfOP5mo ago
No description
Alf
AlfOP5mo ago
yo i thihnk it worked
Alf
AlfOP5mo ago
what do i do about this for emil!?"!
No description
Alf
AlfOP5mo ago
@Isaac McFadyen | YYZ01, EWR01 whats the webhook how to put there @Isaac McFadyen | YYZ01, EWR01 bro it doesnt show in email workers
Idle
Idle5mo ago
which part of "do not ping community members" is so difficult to understand?
Alf
AlfOP5mo ago
idk bro bro im sorry why aint it in email workers can someone just help same script in email worker cant import html ty thingy
Want results from more Discord servers?
Add your server