Topic: User aliases with regular expressions
======== Required information ====
- iRedMail version: 0.9.0
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Apache
- Linux/BSD distribution name and version: Ubuntu 14.04.02 (Lubuntu on Banana Pi)
- Related log if you're reporting an issue:
====
I've seen several queries about email address aliases based on a regular expression several times, but no real answer other than "create an alias for each possible address" which won't work for me.
What I needed was for anything that started with, for example, "foo." to be redirected to "foo@example.com". So if I wanted to sign up at, say, Costco, with an email address, I could use "foo.costco@example.com" and it would go to my real address of "foo@example.com"
I made some simple configuration changes to make this work:
1) First I added an "isregex" column to the alias table: ALTER TABLE alias ADD COLUMN isregex TINYINT(1) NOT NULL DEFAULT 0;
2) Next I created a new file, /etc/postfix/mysql/virtual_alias_maps_regexp.cf. Most of this is the same as all the other files in the directory. The difference is the "query" line:
query = SELECT alias.goto from alias,domain WHERE '%s' REGEXP CONCAT('^',alias.address,'$') AND SUBSTRING(alias.address,1,1) != '@' AND alias.isregex = 1 AND alias.domain='%d' AND alias.domain=domain.domain AND alias.active=1 and domain.backupmx=0 domain.active=1
3) add a reference to the above created file to the virtual_alias_maps entry in /etc/postfix/main.cf file. I added it between the entries for "virtual_alias_maps.cf" and "domain_alias_maps.cf". The part I added was:
proxy:mysql:/etc/postfix/mysql/virtual_alias_maps_regexp.cf,
4) Finally, I inserted the new alias into the database:
INSERT INTO alias (address, goto, domain, isregex) VALUES ('foo\..+@example.com', 'foo@example.com', 'example.com', 1);
This alias matches anything that starts with "foo" and a dot, followed by one or more other characters and then @example.com.
And it all works. Now I can use emails such as "foo.costco@example.com" and "foo.bestbuy@example.com" and I can know who is selling their contacts to spammers. BTW, the reason I don't want to just use "costco@example.com" and "bestbuy@example.com" is because I might have different users each using their own aliases: "foo.costco@example.com" and "bar.costco@example.com".
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.