0

I am configuring a Postfix server in a test environment. It can only forward local emails. Outbound email must be redirected to /dev/null or to a local account. I found a solution on your forum but it unfortunately does not work properly. I do not have much experience with Postfix. Please help me.

/etc/postfix/main.cfg

compatibility_level = 2
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
inet_interfaces = all
inet_protocols = all
myhostname = host.mail1.test
mydomain = mail1.test
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, $mydomain
mynetworks_style = subnet
relay_domains = [mail1.test]:587
smtpd_client_restrictions = permit_mynetworks
smtpd_helo_restrictions = permit_mynetworks
smtpd_sender_restrictions = permit_mynetworks
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject
header_checks = regexp:/etc/postfix/header_checks
virtual_alias_maps = regexp:/etc/postfix/redirect

/etc/postfix/redirect

/.*@(?!hostname\.localdomain$).*/ mailtrap

/var/log/maillog

Jan  3 12:32:17 mail1-test postfix/trivial-rewrite[49647]: warning: regexp map /etc/postfix/redirect, line 1: Invalid preceding regular expression
Jan  3 12:32:17 mail1-test postfix/cleanup[49648]: warning: regexp map /etc/postfix/redirect, line 1: Invalid preceding regular expression
jacobi
  • 1

1 Answers1

0

You are trying to use a regexp with a negative lookahead (?!) with a regexp map which doesn't support that. You need to replace regexp: with pcre:

AlexD
  • 8,747
  • 2
  • 29
  • 38
  • It gets better. But despite redirecting to the maildrop address nothing is going on. Secondly, the local messages are also redirected to the mail drop and I would prefer that they simply reach the local accounts. – jacobi Jan 03 '22 at 12:34
  • Your regexp specifies that all domains except `hostname\.localdomain` are going to be redirected into `mailtrap` but your configuration specifies `mail1.test` as a local domain. – AlexD Jan 03 '22 at 12:47
  • Yes, I changed the notation : /.*@(?!mail1\.test$).*/ mailtrap According to the logs, everything goes where it should, but the mailtrap account is empty – jacobi Jan 03 '22 at 13:26