There is a need to make a relay server for the company's corporate mail. The need arose due to the presence of some google ip in the spam lists, and this sometimes leads to the fact that letters end up in spam. What exactly is needed? You want gmail to send all outgoing mail through this relay server. However, I did not find the possibility in the Google Workspace control panel to specify data for authorization on the server, only the host and port. It is necessary to limit the possibility of relaying only if the letter is sent from the corporate domain. Tell me, please, how can this be done?
There is a VPS (Ubuntu 22.04) server on hetzner with raised postfix (v 3.6.4).
config main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# See www.postfix.org/COMPATIBILITY_README.html -- default to 3.6 on
# fresh installs.
compatibility_level = 3.6
# TLS parameters
smtpd_tls_cert_file=/etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/example.com/privkey.pem
smtpd_tls_security_level=may
smtp_use_tls=yes
smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
myhostname = mail.example.com
mydomain = mail.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = localhost.$mydomain, localhost, $myhostname
relayhost =
#relay_domains = gmail.com, google.com, mail.example.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
milter_protocol = 2
milter_default_action = accept
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
With these settings, I get an error that Relay access denied. This can be fixed by adding the subnets of Google mail services to the "mynetworks =" line, only with this configuration it is like an open relay server and there is a lot of spam from Google mail (thanks for explaining this point to me in the post: Postfix block spam email address ).
Jun 20 08:49:19 mail postfix/smtpd[1444537]: NOQUEUE: reject: RCPT from mail-qk1-f200.google.com[209.85.222.200]: 554 5.7.1 : Relay access denied; from= to= proto=ESMTP helo=
Jun 20 08:49:19 mail postfix/smtpd[1444537]: disconnect from mail-qk1-f200.google.com[209.85.222.200] ehlo=2 starttls=1 mail=1 rcpt=0/1 bdat=0/1 quit=1 commands=5/7