As the postfix-redis
package, so it can be installed without compiling.
This is a patch to the postfix 3.4.3+ MTA to add a lookup table for redis database.
This patch depends on hiredis client library.
Apply the patch to a vanilla postfix 3.4.3+ source tree
Copy dict_redis.c and dict_redis.h files to the postfix/src/global directory.
Copy the postfix-redis.patch to the postfix folder and apply with patch -p2 -i postfix-redis.patch
$ make makefiles CCARGS="-DHAS_REDIS $(pkg-config --cflags hiredis)" AUXLIBS_REDIS="$(pkg-config --libs hiredis)" config_directory=/etc/postfix meta_directory=/etc/postfix daemon_directory=/usr/libexec/postfix shlib_directory=/usr/lib/postfix dynamicmaps=yes shared=yes
$ make
$ make upgrade
main.cf:
virtual_mailbox_domains = redis:/etc/postfix/redis-vdomains.cf
virtual_mailbox_maps = redis:/etc/postfix/redis-vmailbox-maps.cf
virtual_alias_maps = redis:/etc/postfix/redis-valias-maps.cf
host = 127.0.0.1
port = 6379
prefix = (none)
redis-vdomains.cf:
host = 127.0.0.1
port = 6379
prefix = VMD:
redis-vmailbox-maps.cf:
host = 127.0.0.1
port = 6379
prefix = VMM:
redis-redis-valias-maps.cf:
host = 127.0.0.1
port = 6379
prefix = VAM:
Example Redis keys and values:
1) "VMD:example.com" "example.com"
2) "VMM:[email protected]" "[email protected]"
3) "VAM:[email protected]" "[email protected]"
To test the lookup table you can postmap the string as follows, and monitor redis with redis-cli monitor
.
$ postmap -q "[email protected]" redis:/etc/postfix/redis-valias-maps.cf
virtual_mailbox_domains
$ redis-cli set VMD:example.com example.com
virtual_mailbox_maps
$ redis-cli set VMM:[email protected] [email protected]
virtual_alias_maps
$ redis-cli set VAM:[email protected] [email protected]