Email routing worker, modifying email before forwarding

I would like to ask if there is any way to modify the subject of mail that is accessed by email worker before forwarding it. I tried for last 4 days, every solution i came up with threw me a error.

When i tried to modify he headers. It trew me error (i dont have the exact log), but it meant that i cannot modify the original headers.

When i tried to forward other message, i created exactly same message in which i could change the headers with same structure. It threw me this error
“name”: “TypeError”,
“message”: “Illegal invocation”,

Then i tried to see how .forward() func is structered so i could recreate it. I wasnt able to find what it does or how its structured (I think its due to security).

in my project i need to change it from

subject: “[subject]”
to
subject: “[custom text], mail: [mail to which it was sent], subject: [subject]”

[subject] is the original subject
[mail to which it was sent] is mail in receiving mail, due to me having the worker linked with all adresses.

My codes are dead end, because cloudflare is blocking the actions. If you think they could help i can post it here.

I understand that for privacy/security reason it is blocked to modify the headers, but if its for my own purpuse, there should be way to modify them or atleast modify the subject.

If you got any clue how it coud be done it would help.
Thank you…

Using .Forward’s optional headers parameter, Only X-* headers are allowed to be changed.

.Forward is meant to only allow you to forward mail you have received onto your dest. with minimal changes.

If your destination is verified, you could use the Send from Email Workers Binding and use the existing message.raw, just changing the subject: Send emails from Workers (beta) · Cloudflare Email Routing docs
Or you could use some third party email service (mailgun, ses, sendgrid, postmark) and modify the email and send it via them.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.