Limited, regex-based catch-all email addresses

Hello,

I would like to set up a regex-based catch-all email address for my domains, such as:

tom-.*@domain.com

I would rather not have to log in and create an alias every time I need such email address as I do it on the spot, multiple times a day and must have “generated” hundreds of these addresses over the last decade.

Google supports something similar after a “plus”: [email protected]

Is this possible?

Thank you!

Plus addresses (sometimes called subaddresses) are part of the SMTP protocol, and are widely (but not universally) supported. See RFC5233 for details.

Only if you build your own email worker.

I would expect plus addresses to be supported by Email Routing at some stage (might take years perhaps), but I doubt you will ever get RegEx based support without Workers.

3 Likes

Thank you, @michael I’ll look into creating my own email worker.

I can’t find anyone out there who has posted worker code to handle the plus in an email address properly, so I wrote this. It passes the test email triggers, but after deployment and pointing my catch-all to this worker, emails still bounce.

I’ve replaced my email&domain with ~email~ and ~domain~ in the code below

export default {
async email(message, env, ctx) {
if (RegExp(‘^~email~\+’).test(message.headers.get(‘to’))) {
await message.forward(‘~destination~@~domain~’);
} else {
message.setReject(‘Address not valid’)
}
}
}

A little bit of tweaking and I have this working now.

See this feature request thread for full working code.