In that quickie article we will setup Postfix as yandex relay that servers only local mail (emails for root) on AlmaLinux 8.
dnf install postfix mailx cyrus-sasl-plain
nano /etc/postfix/main.cf
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 = localhost inet_protocols = all mydestination = $myhostname, localhost.$mydomain, localhost unknown_local_recipient_reject_code = 550 alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases 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 sendmail_path = /usr/sbin/sendmail.postfix newaliases_path = /usr/bin/newaliases.postfix mailq_path = /usr/bin/mailq.postfix setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /usr/share/doc/postfix/samples readme_directory = /usr/share/doc/postfix/README_FILES 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 smtp_tls_CApath = /etc/pki/tls/certs smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt meta_directory = /etc/postfix shlib_directory = /usr/lib64/postfix myhostname = servername mydomain = domainname.net local_transport = error: this is a null client myorigin = $myhostname.$mydomain mynetworks = 127.0.0.0/8 [::1]/128 relayhost = [smtp.yandex.ru]:465 disable_dns_lookups = yes virtual_alias_maps = hash:/etc/postfix/virtual smtp_sasl_auth_enable = yes smtp_sasl_password_maps = static:yourmailbox@yandex.ru:MAILBOXPASSWORD smtp_sasl_security_options = noanonymous smtp_tls_security_level = encrypt smtp_tls_wrappermode = yes sender_canonical_classes = envelope_sender,header_sender smtp_header_checks = regexp:/etc/postfix/header_check sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps
nano /etc/postfix/virtual
root yourmailbox@yandex.ru
nano /etc/postfix/sender_canonical_maps
/.+/ yourmailbox@yandex.ru
nano /etc/postfix/header_check
/From:.*/ REPLACE From: yourmailbox@yandex.ru
postmap /etc/postfix/virtual
systemctl start postfix && systemctl enable postfix
Send test letter via echo “Test” | mail -s “Test ” root and check your mailbox.