When sending an email, SMTP servers can indicate a transient failure with a 4xx code, or a permanent failure with a 5xx code. On receiving a permanent failure, clients should generate a bounce back to the sender. On receiving a transient failure response, clients should retry sending at a later time and only bounce if persistently unsuccessful.
I’m trying to develop an Email Worker that calls a web service to determine how to route the email. I’d like to be be able to return a transient failure if that web service is temporarily unavailable (pushing the responsibility for retrying to the sender).
However, as far as I can see, the runtime API only supports rejecting with a permanent failure. If the email function raises an exception, a permanent failure is returned to the client after the DATA command:
521 Upstream error, please check https://developers.cloudflare.com/email-routing/postmaster for possible reasons why. KWaqMsZ4iOmY
I would have expected that an unhandled exception would result in a transient failure rather than a permanent failure.
Is there any way to return a transient failure from an Email Worker?