0

I deleted my post and re-created it to be as clear as possible. I m a beginner with postfix. So, I have a postfix server relaying mail to my exchange 2016 server. I want all domain users to be allowed to send email from postfix server to exchange.

here is a simple working situation (Domain1 is local domain (Active directory) and domain2 is an external mail domain) :

[root@srv-relayhost ~]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
compatibility_level = 2
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
header_size_limit = 409600
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
meta_directory = /etc/postfix
mydomain = domain1.com
myhostname = srv-relayhost.domain1.com
mynetworks = xx.xx.xx.xx/32, yy.yy.yy.yy/32, zz.zz.zz.zz/32, 127.0.0.0/8
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix/README_FILES
relay_domains = $mydestination
relayhost = xx.xx.xx.xx
sample_directory = /usr/share/doc/postfix/samples
sender_canonical_classes = envelope_sender, header_sender
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
shlib_directory = /usr/lib64/postfix
smtp_generic_maps = pcre:/etc/postfix/generic.pcre
smtp_header_checks = regexp:/etc/postfix/header_check
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_CApath = /etc/pki/tls/certs
smtp_tls_security_level = may
smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
smtpd_tls_security_level = may
unknown_local_recipient_reject_code = 550


cat sasl_passwd
xx.xx.xx.xx postfix_relayhost@domain1.com:mypasswd


cat generic.pcre
/root@test.domain1.com/ postfix_relayhost@domain2.com
/srv_wsus@domain2.com/ postfix_relayhost@domain2.com
/copieur@domain2.com/ postfix_relayhost@domain2.com

header from is rewrited using this file

cat header_check
/^From: srv_wsus@domain2.com/ REPLACE From: "srv"
/^From: copieur@domain2.com/ REPLACE From: "copieur"
/^From:[[:space:]]+(.*)/ REPLACE From: "${1}"

Two examples of tests (made from Linux machine, test.domain1.com).

echo | mutt -s "OK" -e 'my_hdr From: SAVE_SWITCHS <xx@server.domain1.com>'  -- user@domain2.com
echo | mutt -s "OK" -e 'my_hdr From: SAVE_SWITCHS <xx@server.domain1.com>'  -- user@domain1.com

All is OK.

Now, what i want is mapping all users of domain2 to postfix_relayhost@domain2.com to allow them sending email.

in generic.pcre, i added the last line

/.*@domain2.com/ postfix_relayhost@domain2.com

But now only second test works (echo | mutt -s "OK" -e 'my_hdr From: SAVE_SWITCHS <xx@server.domain1>' -- user@domain1.com). I can't receive mail for the first test. I only receive mail sent to domain1. Maybe regex is incorrect. So I tried with a script to fill my generic file

rm -f /tmp/mail
ldapsearch -H ldap://xxxx -x -D 'user@domain1.com' -w 'pass' -b 'dc=domain1,dc=com' -s sub "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" mail | grep "mail:" | cut -d " " -f 2 > /tmp/mail
while read LIGNE
    do
    cat /etc/postfix/generic.pcre | grep $LIGNE
    if [ $? == 1 ]
        then
        echo "/$LIGNE/ postfix_relayhost@domain2.com" >> /etc/postfix/generic.pcre
    fi  
    done < /tmp/mail
rm -f /tmp/mail
postmap /etc/postfix/generic.pcre
service postfix restart

But issue is the same. I only receive mail sent to domain1. user@domain2.com is mapped in generic.pcre. When i delete this mapping, everything works. user@domain2.com is a known user (main mail address) for my exchange server. Can you help to all users of domain2 to postfix_relayhost@domain2.com to allow them sending email? Thank you.

Alex Lum
  • 145
  • 1
  • 4
  • 16

1 Answers1

0

My bad, i forgot sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps

here is the solution : https://serverfault.com/a/674984/284549

I can delete this topic if it is irrelevant.

Alex Lum
  • 145
  • 1
  • 4
  • 16