Email Routing, API To Setup Addresses

Howdy, Looking through the docs I don't see a progrmattic way to setup email addresses for email routing. I need to setup dynamic mailbox for workers to process each one. Is there no way to do this through an API? Logging inot the dashboard to setup the email is just silly. Am I missing something here? Here is my high level use case [email protected] --> Routes to Email Worker --> email worker does some tasks on email, logs it to D1 and then is displayed in my web application. I know email workers can handle everything I need but GETTING the mailbox configured does not see to be an easy API call or again am I missing something?
3 Replies
Chaika
Chaika3mo ago
The API is create routing rules: https://developers.cloudflare.com/api-next/resources/email_routing/subresources/rules/methods/create/ The dashboard uses the same api for this, inspecting it is a good way of learning how it does stuff. In this case the action if of type 'worker' and the value is just the worker name, rest of the matching syntax is the same You could also just configure a wildcard to your worker and handle the validation within
Cloudflare API | Email Routing › Rules › Create Routing Rule
Interact with Cloudflare's products and services via the Cloudflare API
csmykay
csmykayOP3mo ago
I see. But this just allows me to create the desitnation, like another email or worker: https://developers.cloudflare.com/api-next/resources/email_routing/subresources/addresses/methods/create/ But just so I am clear there is not a way to create an actual custom address. That I have to do through the dashboard is that correct? Are you saying just create a wildcard address to an email worker and I then check for all the logic, for example the "procect_id" in my example? I supposes that can work. Not a horrible idea but I do find it odd that there is no API to provision custom addresses for email.
Cloudflare API | Email Routing › Addresses › Create A Destination A...
Interact with Cloudflare's products and services via the Cloudflare API
Chaika
Chaika3mo ago
What do you mean? The Routing Rules are what the "Custom Addresses" are /routing/addresses is the Emails you can use as targets/forward to from email workers. Routing Rules https://developers.cloudflare.com/api-next/resources/email_routing/subresources/rules/methods/create/, are the Routing Rules -> Custom Addresses tab Worth noting: The dashboard uses all the same endpoints which are available in the public API just dash.cloudflare.com/api/v4/<path> -> api.cloudflare.com/client/v4/<path> Same bodies and responses. Inspect element/dev tools -> network. There are some undocumented APIs it uses though which can change at any time, and there are a few that are dashboard only like registrar new domains and verifying emails
Want results from more Discord servers?
Add your server