I would like my postfix server to act as a relay/smarthost for some clients, but would like to deliver all mail to a local (Maildir-style) mailbox instead of sending on to the intended recipient. Sounds a bit weird, I know, but it is intended for testing purposes on our test environments.
For our live environment, I would like to deliver mail normally.
My current main.cf
looks like this:
myhostname = mymail.mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = pcre:/etc/postfix/mydestinations
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.5.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 192.168.5.43, 127.0.0.1
inet_protocols = all
virtual_alias_maps = hash:/etc/postfix/virtual
default_process_limit = 100
smtpd_client_connection_count_limit = 10
smtpd_client_connection_rate_limit = 30
queue_minfree = 20971520
header_size_limit = 51200
message_size_limit = 10485760
smtpd_recipient_limit = 100
smtpd_tls_cert_file=/etc/ssl/certs/mailcert.crt
smtpd_tls_key_file=/etc/ssl/private/mailcert.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_security_level=may
smtpd_tls_protocols = !SSLv2, !SSLv3
/etc/postfix/mydestinations:
/^mymail.mydomain.com$/ ACCEPT
/^localhost.localdomain$/ ACCEPT
/^localhost$/ ACCEPT
/^.*\.mydomain\.com$/ ACCEPT
/etc/postfix/virtual:
@mydomain.com catchall
I've been told this is possible, but can't really find any specific info as to how to achieve it..
I see two different problems with your current configuration:
Your domains are in
mydestination
while you are trying to implement your catch-all address usingvirtual_alias_maps
, which would require the domains to be invirtual_alias_domains
.You only have
@example.com
in yourvirtual_alias_maps
, while the regular expression^.*\.example\.com$/
suggests you would need this catch-all for every*.example.com
. In order to do that you'd need to be able to use regular expression on yourvirtual
, too. Since this is not possible withhash:
, you'd need to usepcre:
here, too.You need to modify these settings in your
main.cf
:And your
/etc/postfix/virtual
would have this regular expression:If you use
pcre:
make sure that your Postfix is built with the PCRE support. You also have an option to useregexp:
, instead, but you won't be able to use the Perl style regular expressions. See Postfix Lookup Table Overview:Someone showed me a config that worked:
(abbreviated) /etc/postfix/main.cf:
/etc/postfix/recipient_canonical_map:
This leads to the desired outcome for mail delivery:
Dec 1 09:40:42 mailserver postfix/qmgr[7943]: 58242139670: from=, size=703, nrcpt=1 (queue active) Dec 1 09:40:42 mail-it-int postfix/smtpd[7944]: disconnect from unknown[192.168.5.2] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5 Dec 1 09:40:42 mail-it-int postfix/local[7949]: 58242139670: to=, orig_to=, relay=local, delay=0.01, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
...and the mail intended to be routed externally is diverted to a local mailbox