TransWikia.com

Postfix as incoming and outgoing relay

Server Fault Asked by meilon on December 9, 2021

I’d like to replace a peace of legacy Windows email gateway software with a postfix 3.5 container and I can’t seem to pull of both features at the same time:

  • It should accept incoming mails (@ourdomain.com) from any IP if the address is in the relay_recipient_maps and forward it to the exchange server.
  • It should accept outgoing mails (ex. @anydomain.net) only from specific IP addresses with any [email protected] and relay those through the exchange as well.

Here’s the configuration I’m currently using:

# differences from postconf -d
compatibility_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 = 4096000
inet_protocols = ipv4
local_transport = error:local mail delivery is disabled
manpage_directory = /usr/share/man
message_size_limit = 50000000
mydestination =
mydomain = ourdomain.com
myhostname = smtp-demo.ourdomain.com
mynetworks = /etc/postfix/mynetworks
myorigin = ourdomain.com
parent_domain_matches_subdomains = debug_peer_list smtpd_access_maps
process_id = 137
readme_directory = /usr/share/doc/postfix/readme
relay_domains = ourdomain.com
relay_recipient_maps = hash:/etc/postfix/relay_recipients
relayhost = exchange.ourdomain.com
smtp_tls_security_level = may
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks,reject_invalid_helo_hostname,permit
smtpd_recipient_restrictions = permit_auth_destination,reject_non_fqdn_recipient, reject_unknown_recipient_domain, check_sender_access hash:/etc/postfix/allowed_senders, reject
smtpd_relay_restrictions = permit_mynetworks,reject_unauth_destination
smtpd_sender_restrictions = permit_mynetworks


# /etc/postfix/mynetworks
10.176.204.50
10.176.201.100
...

# /etc/postfix/relay_recipients
[email protected] OK
[email protected] OK
...

# /etc/postfix/allowed_senders
ourdomain.com OK

Everytime I change something in smtpd_recipient_restrictions or smtpd_relay_restrictions I get one of the two objectives to work, but then I break the other one. With the current config I get no error after RCTP TO an external address from a client not in the mynetworks file. Container networking is set up correctly, the correct IP of the clients I’m testing with is shown in the logs, so mynetworks should work.

What am I doing wrong?

One Answer

If you can't come up with settings that can fulfill both requirements, you can refer to Managing multiple Postfix instances on a single host. You could configure submission with different settings through master.cf, e.g.

submission  inet n       -       y       -       -       smtpd
  -o smtpd_client_restrictions=permit_mynetworks,reject
  -o smtpd_relay_restrictions=permit_mynetworks,reject
  -o smtpd_recipient_restrictions=reject_unknown_recipient_domain,permit_mynetworks,reject

This will open submission port 587 for the outbound relay.

If you must use port 25 for both, you can also bind the instances to different IP addresses.

Answered by Esa Jokinen on December 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP