regexmailgun

Can use regular expression to forward mail in Mailgun?


I am trying to forward all mail targeting one domain to different domain using only one route like this:

Filter: .*@mail.domain.com

Forward: *@domain.com

The syntax for the "Forward" is what I cannot get to work and cannot find an example.


Solution

  • You need to use named capture groups, see doc:

    Explanation- we want Mailgun to receive and forward the incoming message to an external domain, but retain the user to user mapping. To do this, we use a named capture. The named capture will remember the “user” and use it in the forward action.

    So this should work:

    match_recipient('(?P<user>.*?)@mail.domain.com') -> forward('g<user>@domain.com')