can a worker parse an JSON email attachment and connect with an API?
I'm new to this and seeing if this is a viable option for what I'm trying to do.
I have a bed and breakfast, and my system sends out a JSON attachment in an email everyday with the day's guests and their contact info. I need to get the phone numbers from that attachment and send it to an API to update door codes.
Is this an appropriate use case for workers? If so, Where should I get started?
4 Replies
Hi @AdmiralNines what you describe is viable with email workers as described in the docs
You'll have to do a bit of work in the worker code to parse the raw email body with attachments and then extract the numbers to send to your API.
If you're in control of the system generating those emails, it may be simpler to post the JSON directly to an HTTP API hosted in a worker.
(I may be wrong about this, but developing workers which handle HTTP requests is still a bit easier to test locally with
wrangler dev
than building email workers)Cloudflare Docs
Email Workers | Cloudflare Email Routing docs
With Email Workers you can leverage the power of Cloudflare Workers to implement any logic you need to process your emails and create complex rules. These rules determine what happens when you receive an email.
Thanks for the reply Jürgen! Unfortunately I don't have control of the system that is sending out the emails. I'm just happy that I was able to get it to send me a JSON format 🙂
Yeah, I've installed node and am trying to work on understanding the the workflow of developing an email worker locally. I've dabbled in js but am aways from proficient, so this'll be a bit of an uphill battle for me.
I managed to deploy a basic email worker to my own account today, and it parses attachments using this library.
My code is on github - feel free to clone and use it as a starting point.
Since you need the library, you can't just try it in the online editor, you'll need to setup your local wrangler first.
GitHub
my-email-worker/src/index.ts at main · jldec/my-email-worker
Contribute to jldec/my-email-worker development by creating an account on GitHub.
GitHub
GitHub - postalsys/postal-mime: Email parser for browser and server...
Email parser for browser and serverless environments - postalsys/postal-mime