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
Chaika4mo ago
subject should be directly on the email
Chaika
Chaika4mo 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
AlfOP4mo ago
do i only need to just paste the index.js code into worker?
Chaika
Chaika4mo ago
there's a setup guide in the readme
Alf
AlfOP4mo 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
Chaika4mo ago
oh are you used to the dashboard?
Alf
AlfOP4mo ago
im sorry but now no
Chaika
Chaika4mo 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
AlfOP4mo ago
just bought my first domain today just so i didnt have to keep creating emails
Chaika
Chaika4mo ago
I mean, you're using the Quick Edit in the dashboard over wrangler/local dev
Alf
AlfOP4mo ago
and i wanted discord to be like gmail yeah think so
Chaika
Chaika4mo 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
AlfOP4mo 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
Chaika4mo 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
AlfOP4mo ago
i cant watch videos its banned in my country
Erisa
Erisa4mo ago
the first link is the text form you can follow that instead
Alf
AlfOP4mo ago
@Chaika @Erisa bro it keeps telling me to install nom where tf is npm im actually turning mad from this
gwapes
gwapes4mo ago
npm stands for node package manager, it comes when you install node. Node is a runtime for JavaScript.
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
bro tf is this shi
Alf
AlfOP4mo 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
AlfOP4mo ago
@Erisa bro @Erisa @Chaika
John Spurlock
John Spurlock4mo ago
?pings
Flare
Flare4mo 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
AlfOP4mo ago
sorry mate just people are begging me to finish
gwapes
gwapes4mo 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
AlfOP4mo ago
bro im doing this on vscode on cloudflare website they aint got a terminal
gwapes
gwapes4mo ago
There will be a cmd you can paste
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
bro its broken asf
gwapes
gwapes4mo ago
You can just do wrangler init —from-dash <worker-name>
Alf
AlfOP4mo ago
where tf is that bro pls can i just screenshare u
gwapes
gwapes4mo ago
On the Cloudflare dashboard Where you make a worker
Alf
AlfOP4mo ago
bro lemme screenshare i beg 🙏
gwapes
gwapes4mo ago
No, it’s not rocket science
Alf
AlfOP4mo ago
it fricking is
gwapes
gwapes4mo ago
I gave you the things you need
Alf
AlfOP4mo ago
bro im confsued asf
gwapes
gwapes4mo ago
Go to the dashboard, make a new worker
Alf
AlfOP4mo ago
ok bro i will pay u to goto dms and lemme screenshare
gwapes
gwapes4mo 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
AlfOP4mo ago
maybe im more special and need to screenshare to someone u dont gotta speak
gwapes
gwapes4mo ago
Can you not go to the dashboard?
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
click this button yes?
gwapes
gwapes4mo ago
Yes
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
what todo here just press deploy?
gwapes
gwapes4mo ago
There’s a big fat deploy button Yes
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
where now @gwapes
gwapes
gwapes4mo ago
Try the wrangler cli
Alf
AlfOP4mo ago
where now
Alf
AlfOP4mo ago
No description
gwapes
gwapes4mo ago
Ok nvm go back, and click “edit code”
Alf
AlfOP4mo ago
no i installed wrangler do i delete
gwapes
gwapes4mo ago
Go here and click edit code
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
ok @gwapes now what
gwapes
gwapes4mo ago
Bro please stop pinging me every time
Alf
AlfOP4mo ago
oh sorry
gwapes
gwapes4mo ago
They also changed the layout… Ok wrangler init —from-dash helloworld-webhook — it’s two -‘s
Alf
AlfOP4mo ago
alright where do i put that
gwapes
gwapes4mo ago
In vscode
Alf
AlfOP4mo ago
in my computer terminal?
gwapes
gwapes4mo ago
Terminal
Alf
AlfOP4mo ago
okty
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
not really
gwapes
gwapes4mo ago
Put npx before wrangler
Alf
AlfOP4mo ago
No description
gwapes
gwapes4mo 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
AlfOP4mo ago
No description
gwapes
gwapes4mo ago
Do this instead
Alf
AlfOP4mo 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
gwapes4mo 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
AlfOP4mo ago
bro i typed all that out how to set secret without npx
gwapes
gwapes4mo ago
Could just paste it straight into the code lol
Alf
AlfOP4mo ago
my ctrl y isnt working
Isaac McFadyen
Isaac McFadyen4mo ago
You used an emdash instead of a regular dash which is - You should be using two regular dashes like --
gwapes
gwapes4mo ago
Thought so, I knew something looked funky. iOS seems to have funny -‘s
Isaac McFadyen
Isaac McFadyen4mo ago
Yeah it's Apple's "smart dashes" and "smart quotes", they sometimes mess things up.
Alf
AlfOP4mo ago
npx wrangler init --from-dash "helloworld-webhook"
Isaac McFadyen
Isaac McFadyen4mo ago
Yes, like that.
Alf
AlfOP4mo ago
like this
gwapes
gwapes4mo ago
Not that smart then But you don’t need that if you cloned the repo
Alf
AlfOP4mo ago
it aint working cloned
gwapes
gwapes4mo ago
You can just put the worker name in the .toml file and then do wrangler deploy which will do it
Alf
AlfOP4mo ago
No description
gwapes
gwapes4mo ago
I also have 0 idea on how the email routing works
Alf
AlfOP4mo ago
alright what now
Isaac McFadyen
Isaac McFadyen4mo ago
What is "not working"? Are you getting an error?
Alf
AlfOP4mo ago
says require aint defined
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
also what stops someone else accessing my worker through terminal?
Isaac McFadyen
Isaac McFadyen4mo 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
AlfOP4mo ago
i didnt need any authorization
Isaac McFadyen
Isaac McFadyen4mo ago
You don't have a fetch handler so they can't do that.
gwapes
gwapes4mo ago
I mean if you have a shared computer then, well, don’t let them on it. Otherwise nothing
Isaac McFadyen
Isaac McFadyen4mo 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
AlfOP4mo ago
bro
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
what tf is this why it still say require
Isaac McFadyen
Isaac McFadyen4mo ago
Change: const parser = new PostalMime.default(); to: const parser = new PostalMime();
Alf
AlfOP4mo ago
No description
Alf
AlfOP4mo ago
yo i thihnk it worked
Alf
AlfOP4mo ago
what do i do about this for emil!?"!
No description
Alf
AlfOP4mo ago
@Isaac McFadyen | YYZ01, EWR01 whats the webhook how to put there @Isaac McFadyen | YYZ01, EWR01 bro it doesnt show in email workers
Idle
Idle4mo ago
which part of "do not ping community members" is so difficult to understand?
Alf
AlfOP4mo 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