Enable Relay and Rewrite Sender for Postfix in Plesk for MS 365 or Google Workspace

See the following tutorial for enabling relay and sender rewriting for Plesk and Postfix. Rewrites are important when relaying via 365 as you must use the mailbox sender address, Google will deliver the email regardless of sender.

cd /etc/postfix

Create a hashed password file for the SMTP server, or use nano.

nano sasl_passwd
echo "smtp.office365.com:587 user@domain.com:password" > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
rm /etc/postfix/sasl_passwd

Create an smtp_header_checks file, or use nano.

echo "/^From:.*/ REPLACE From: My Plesk <itsupport@myplesk.com>" > /etc/postfix/smtp_header_checks

Add the following code to the end of main.cf:

# header checks to rewrite
smtp_header_checks = pcre:/etc/postfix/smtp_header_checks

# smart host forwarding
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
relayhost = smtp.office365.com:587