Email worker cannot reply to emails received on a subdomain

What is the name of the domain?

staging.example.com

What is the error message?

Error: mail from is not from the correct domain

What is the issue you’re encountering

I have an email route on [email protected] that triggers a worker. The worker tries to reply to this email, setting [email protected] as its “from” address, and thereby complying with the requirement that the outgoing sender domain must match the same domain that received the email. This same worker runs successfully when on the root domain, i.e. on [email protected].

What are the steps to reproduce the issue?

  1. Create an email worker that replies “Hello World” to all incoming emails, sending from the same domain as the recipient of the incoming email.
  2. Add an email route to the worker on a subdomain
  3. Send an email to that route