Using Postifx as a Relay on MacOS

Local Postfix relying to Google’s SMTP server

The intent is to use the postfix system install to relay email to Google’s SMTP server.

Configure mail aliases

/etc/aliases is a symlink to /etc/postfix/aliases, it can be updated to redirect root or any other user’s email to another address:

root: my.email@domain.tld
userX: my.email@domain.tld

Aliases database should updated:

sudo postalias /etc/postfix/aliases

Altering postfix configuration

/etc/postfix/main.cf should be tuned:

myhostname = Baptistes-MacBoo-Pro.local
(...)
# inet_protocols = all
(...)
# https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay/
# https://www.justinsilver.com/technology/osx/send-emails-mac-os-x-postfix-gmail-relay/
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
smtp_sasl_security_options =
smtp_sasl_mechanism_filter = AUTH LOGIN
inet_protocols = ipv4
virtual_alias_maps = hash:/etc/postfix/virtual

Adding virtual entries

In order to map local address to fully qualified address, /etc/postfix/virtual should be updated:

baptiste my.email@domain.tld
baptiste@Baptistes-MacBook-Pro.local my.email@domain.tld

Then the virtual map should be updated

sudo postmap /etc/postfix/virtual

Starting the local postfix as a daemon

sudo postfix start

Checking postfix logs

log stream --predicate '(process == "smtpd") \
  || (process == "smtp") \
  || (process == "master")' --info

Checking conf after a MacOS update

When MacOS gets updated it can alter the configuration changes and revert to default settings or let you review the changes they made to the default configuration files. You can check any ~orig files having been created under /etc/postfix as well as default files ending in _default available under ~/Desktop/Relocated Items/Configuration.


240 Words

2020-04-21 12:53 +0000