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