0

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..

1

I see two different problems with your current configuration:

  • Your domains are in mydestination while you are trying to implement your catch-all address using virtual_alias_maps, which would require the domains to be in virtual_alias_domains.

  • You only have @example.com in your virtual_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 your virtual, too. Since this is not possible with hash:, you'd need to use pcre: here, too.

You need to modify these settings in your main.cf:

mydestination = localhost
virtual_alias_domain = pcre:/etc/postfix/mydestinations
virtual_alias_maps = pcre:/etc/postfix/virtual

And your /etc/postfix/virtual would have this regular expression:

/@((\w[\w\-]*)\.)+example\.com/ catchall

If you use pcre: make sure that your Postfix is built with the PCRE support. You also have an option to use regexp:, instead, but you won't be able to use the Perl style regular expressions. See Postfix Lookup Table Overview:

pcre (read-only)

A lookup table based on Perl Compatible Regular Expressions. The file format is described in pcre_table(5). The lookup table name as used in pcre:table is the name of the regular expression file.

regexp (read-only)

A lookup table based on regular expressions. The file format is described in regexp_table(5). The lookup table name as used in regexp:table is the name of the regular expression file.

| improve this answer | |
0

Someone showed me a config that worked:

(abbreviated) /etc/postfix/main.cf:

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = mydomain.com, localhost, $myhostname


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

recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_map

/etc/postfix/recipient_canonical_map:

/./  catchall

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.