Send Emails on Mac OS X with Postfix and a Gmail Relay
A quick howto setup Mac OS X and Postfix to use Gmail as a relay. Everything will need to be executed as
sudo. If you just need to send emails try running
sudo postfix start, and make sure to check your spam for emails – they will likely be flagged as they originate from a local mail server.
Connecting to the Gmail SMTP server requires both SSL and authentication. To set up authentication you will need to edit the
sudu vi /etc/postfix/sasl_passwd
Update the contents to include the following. Note that enclosing hostnames with square brackets –
 – tells Postfix to avoid doing an MX lookup. Make sure to replace
PASSWORD with your Gmail password, properly escaping any colons in it.
postmap command to update the SASL credentials in Postfix.
sudo postmap /etc/postfix/sasl_passwd
Postfix Relay Configuration
Next we need to edit the Postfix configuration found in
sudo vi /etc/postfix/main.cf
I was not able to route mail to the Gmail SMTP servers over IPv6, so force only IPv4 connections by searching for the
inet_protocols key and updating the value.
inet_protocols = ipv4
If any of the following keys already exist in your configuration comment them out, and include the following at the bottom of the config file.
# Gmail SMTP relay relayhost = [smtp.gmail.com]:587 # Enable SASL authentication in the Postfix SMTP client. smtpd_sasl_auth_enable = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = smtp_sasl_mechanism_filter = AUTH LOGIN # Enable Transport Layer Security (TLS), i.e. SSL. smtp_use_tls = yes smtp_tls_security_level = encrypt tls_random_source = dev:/dev/urandom
Restart Postfix & Test
Restart Postfix as root, then send a test email.
sudo postfix stop && sudo postfix start date | mail -s "Test Email" YOUR_EMAIL@gmail.com
If you don’t receive the test email, check the Postfix queue by running
mailq or looking at the contents of
/var/log/mail.log. Any errors that mention “
SASL authentication failed” indicate that you may have entered an incorrect email/password combination, forgot to run
postmap after updating the credentials, or need to Turn On Access for less secure apps in Gmail for your account.