2

Using Debian 7 I need to setup a mail server configuration for testing purposes. This setup is not intended to "go into production" mode but we need something like this during our development process for a mobile app.

The app requires a user to register with an email address and sends out a confirmation link as lots of services do. However we cannot create hundreds of real email addresses for testing, so the idea would be to define certain wildcards and any address matching this wildcard shall be forwarded to a specific existing email address.

Example

user1_*@mydomain.com --> firstname.lastname@mail.com
user2_*@mydomain.com --> firstname.lastname@googlemail.com

So that...

user1_sdaklfjsh@mydomain.com
user1_3464trh@mydomain.com
user1_lkljkkhjgh@mydomain.com

would all be forwarded to firstname.lastname@mail.com.

Are there any tutorials or guides how to do this?

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
  • Are you strongly preferring postfix for this? I think I can get you really close to what you want if you were using Exim, really easily. – Zoredache Dec 03 '14 at 19:43
  • @Zoredache No, it doesn't matter if it's postfix, Exim, sendmail or whatever. As long as it does the job :-) – Robert Strauch Dec 03 '14 at 19:45
  • 3
    There are plenty of tutorials and guides. Search for **address tagging** and **plus addressing**. This used to be a standard feature with nearly every mail provider at one point. It's still quite common, just most people aren't aware of it. [Gmail has it](https://support.google.com/mail/answer/12096?hl=en). The idea is that anything after the + character is ignored for delivery (it's delivered to the address before the +). [recipient_delimiter](http://www.postfix.org/postconf.5.html#recipient_delimiter) is what you're looking for I believe. –  Dec 03 '14 at 19:46
  • @yoonix Thanks a lot for the Gmail hint. I wasn't aware that they have something like this. That's perfectly fine. – Robert Strauch Dec 03 '14 at 19:49

2 Answers2

3

Doing something like this on Debian with exist should be pretty easy.

Install the exim4-daemon-light package. Configure for Internet mode. Adjust your Exim routers routers as suggested by this patch, and restart.

--- a/exim4/conf.d/router/400_exim4-config_system_aliases
+++ b/exim4/conf.d/router/400_exim4-config_system_aliases
@@ -42,3 +42,6 @@ system_aliases:
   .ifdef SYSTEM_ALIASES_DIRECTORY_TRANSPORT
   directory_transport = SYSTEM_ALIASES_DIRECTORY_TRANSPORT
   .endif
+  local_part_suffix_optional
+  local_part_suffix = +*
+

--- a/exim4/conf.d/router/900_exim4-config_local_user
+++ b/exim4/conf.d/router/900_exim4-config_local_user
@@ -13,3 +13,5 @@ local_user:
   local_parts = ! root
   transport = LOCAL_DELIVERY
   cannot_route_message = Unknown user
+  local_part_suffix_optional
+  local_part_suffix = +*

The above uses the + character to setup sub-addressing, and changes the routers for both the system alias and local mailboxes. You could update the suffix to be _* since that seems to be closer to what you want.

With the above in place you can just add an entry to your /etc/aliases.

user1: firstname.lastname@mail.com
user2: firstname.lastname@googlemail.com
Zoredache
  • 130,897
  • 41
  • 276
  • 420
2

You have to use standard exim feature called rewrite. Look for begin rewrite section and add the next lines:

begin rewrite
user1_*@mydomain.com   firstname.lastname@mail.com         Eh
user2_*@mydomain.com   firstname.lastname@googlemail.com   Eh
Kondybas
  • 6,964
  • 2
  • 20
  • 24