Regex Email Forwarding

Regex (Regular Expressions) is a powerful tool which can be used to extensively customise your aliases. Here are some details about ImprovMX's implementation.


With Regex, you can configure your alias to match a specific pattern. A common pattern that you can setup easily and quickly is the following:

Alias

Forwards to

(contact|support|hello)

richard.hendricks+$1@gmail.com

In this scenario, an email sent to support@piedpiper.com will be forwarded to richard.hendricks+support@gmail.com

Yes, you read that correctly, we allow for substitutions in the regular expression you are using, allowing you to set up complex structures.

You might be a REGEX professional, and seeing a pattern like the one above might raise some eyebrows. Indeed, sending an email to “aaaacontactaaaa@piedpiper.com” would match the above pattern. But in practice, we surround all the regexes entries with the start and end block (“^” and “$“). So when testing, the pattern is, in reality, ^(contact|support|hello)$.


Using substitutions

Standard REGEX rules apply, and you can use the dollar sign (“$”) as a substitution in the forwarded email. The number following the dollar sign starts at 1 for the first group matched (using parenthesis).

This allows you to write interesting REGEX patterns and use the matched value in your destination email. The above example is a case that both leverages REGEX patterns, substitutions and GMail “plus” sign, but depending on your organization and the destination mail server, you can create one alias that will handle your entire organization. If all the emails follow the same pattern firstname.lastname, then it can be configured as ([a-z]+).([a-z]+).

The only restriction that applies is the maximum length of the alias field, which is 150 chars.


Order of importance when matching an email

At ImprovMX, we consider four levels of importance when searching for an alias, which are:

  1. The exact match

  2. The “Plus sign” match (more on that at the bottom of this guide)

  3. The Regex match

  4. The Wildcard or catch-all match *

Regardless of how many aliases an email matches, only the highest priority one will be taken into consideration.

For example, take the following alias configuration for Piedpiper.com:

Alias

Forwards to

contact

richard.hendricks@gmail.com

(contact|support|hello)

dinesh.chugtai+$1@gmail.com

*

gilfoyle+wildcard@gmail.com

An email sent to contact@piedpiper.com would match the three alias configurations in this case, but ImprovMX will use the best match case, which is the exact match: “richard.hendricks@gmail.com”.

Here’s a sample of emails sent, and which alias they’d match based on the configuration above:

Hmm, what about the last line? Yep, this is what we call the “Plus sign” match...

The “plus sign” match

When we receive an email that contains the “+” sign, we handle them like Gmail does, whenever possible.

This means that any email sent to us with a + sign in the left part, will be considered without it when searching for an alias.

In this case, sending an email to contact+anything@piedpiper.com is similar to sending an email to contact@piedpiper.com and will match the same result, which is “richard.hendricks@gmail.com”.

But we go a bit further.

Since the matching email is a @gmail.com address, we already know that they work well with the plus sign too (see the below list for full list of plus sign accepted domains), so if the matching email is a @gmail.com address, and does not already have a “+” sign, we add the one we got in the original email.

Hence, sending an email to contact+anything@piedpiper.com will result in the email being forwarded to richard.hendricks+anything@gmail.com.

The “+anything” part is automatically added by ImprovMX.

Note: This only works for @gmail.com domains, and not for Google Workspace domains as it would require us to test if these domains are hosted by GMail first, slowing the email processing time.

If your email provider also accepts the plus sign, don’t hesitate to let us know. We’ll add them to the list of accepted domains for the plus sign.


List of accepted domains for Regex plus sign forwarding

  • gmail.com

  • hey.com

  • protonmail.com

  • icloud.com

  • fastmail.com

  • outlook.com

  • runbox.com

  • yandex.com

  • yandex.ru

  • mailfence.com

Note: Many of the above email systems (and corporate email services such as Google Workspace and Microsoft 365) can accept plus addressing on a custom domain. However, this has not been implemented on ImprovMX's side as it would require us to test if these domains are hosted by Google / Microsoft first, increasing the email processing time.


Still have questions?

If you have any other queries please get in touch with our support team.


Contact Us

Was this helpful?