RegExCatchAll

This is an old article about some code I haven’t maintained for 6 years. I’ve moved to Office 365 and if you have too, you might be interested how I achieved suffix matching there.

Exchange 2010 LogoRegExCatchAll is a Transport Agent for Microsoft Exchange 2007 and 2010. It provides email suffix matching based on standard .NET regular expressions and can deliver email to Exchange Mailboxes or external SMTP addresses. It stores its configuration in an XML file which can be updated live without restarting any services. It also includes a “banned alias” list, so you can blacklist any of your previously used suffixes.

If you know what this is and why you need it, skip to Github where you can clone the Transport Agent source and compile it yourself. Otherwise read on for more information.

Email Suffixes

Email Suffix Matching is useful feature enabled on some ISPs mail servers. If you have a GMail account you may be familiar with the approach. Say you have an email john@gmail.com. Gmail will actually deliver mail to john+anything@gmail.com; you can add any suffix you like after the + and GMail will still deliver it to your inbox. Some others ISPs support this by allowing you to place a period after the local part so you can use john.anything@example.com. You don’t have to create these email addresses anywhere – you can just start using it and the mail server will make sure it gets to your inbox.

This is fantastically useful because it means that when a website asks for your email address you can give out a custom throwaway email just for that site. So when you sign up at DodgyCo.com, you give them the email john.dodgyco@example.com. If you ever receive spam because DodgyCo sold your email address you’ll know a) who sold you out, and b) which email address to add to your spam filter.

Exchange Server

Exchange Server does not support email suffixes. Every recipient has to have an alias created on the server. If you want to deliver to john.suffix@example.com you need to have created an alias for that user, otherwise the Exchange Recipient Filter will reject the message since – as far as it is concerned – the user does not exist on the server.

Worse, Exchange doesn’t even implement any generic CatchAll functionality. CatchAll would allow the server to redirect messages for non-existing recipients to a specific address. There are some solutions to the CatchAll problem, but none that allow redirection of multiple suffixes to internal and external addresses.

Transport Agents

Exchange Server 2007 and 2010 allow for their functionality to be extended by writing Transport Agents. These can operate on messages as they pass through the transport pipeline. RegExCatchAll is a Transport Agent that looks out for emails addressed to your suffixes (as defined in the config.xml) and delivers them to the mailbox or external address that you define.

The config.xml takes the form:

<config>
	<redirect pattern="^john+\.[a-z]+@domain.com$" address="john@domain.com" />
	<redirect pattern="^jane+\.[a-z]+@domain.com$" address="jane.doe@gmail.com" />
	<banned address="john.spam@domain.com" />
	<banned address="jane.newsletter@domain.com" />
</config>

Here we have configured two regular expressions for suffix matching, redirecting one to an internal mailbox and the second to an external SMTP address. We’ve also created two “banned” addresses. These are previously used suffixes (spam and newsletter) for which we now want to reject delivery.

Purchase

I’ve given enough information here and in the related blog post that a C# developer with some spare time could create this Transport Agent themselves. I used to sell a packaged DLL together with installation scripts but have no open sourced the (very simple) code. Check it out at Github and read up on the install and configuration guide.

NOTE: The source compiles against the DLLS from Exchange 2007, 2010 RTM, 2010 SP1 and 2010 SP2 for x64 only. I have not updated the code for 2010 SP3, nor have I built it against Exchange 2013. The Exchange DLLs are not included..
Microsoft do not support the x86 (32bit) builds of Exchange in production so neither do I.