I use Postfix to relay system messages (e.g. a botched cronjob) over SSL to my Gmail account. These messages are otherwise “lost” because the email is being sent to a dormant mail transfer agent on my Mac. There’s way more that you can do with Postfix, but I’ll just cover the setup I did for my needs.
1. Create the Simple Authentication and Security Layer (SASL) password file.
sudo vi /etc/postfix/sasl_passwd
Enter and save the following
2. Create a Postfix lookup table for SASL.
sudo postmap /etc/postfix/sasl_passwd
3. Configure Postfix with
sudo vi /etc/postfix/main.cf
By default, everything is commented out. You can just append this to the end of file and save:
mydomain_fallback = localhost
mail_owner = _postfix
setgid_group = _postdrop
relayhost=smtp.gmail.com:587
# Enable SASL authentication in the Postfix SMTP client.
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=
# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
5. Start postfix with
sudo postfix start
If you get an error, address the parameter in main.cf that is in the error and use
sudo postfix reload
to refesh Postfix. If everything looks good, then send an email
date | mail -s test your.name@gmail.com
If you don’t get an email fairly quickly, enter
mailq
and you should see the email there along with a description of any problems. If the mail is not in the queue, you most likely got something wrong in main.cf so you’ll need to do some debugging. If your mail queue starts to fill up during this process, you can clear it with
sudo postsuper -d ALL
6. Once you have everything working, you can set Postfix to start on boot by adding a key to /System/Library/ LaunchDaemons/org.postfix.master.plist. If you have Property List Editor (or something similar), you can add the key RunAtLoad of type Boolean with a value that is checked.
Alternatively,
sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist
and add the following just before the tag </dict>
<true/>
You can control whether your job is to be kept continuously running by using KeepAlive .
Tags: Mac Postfix Gmail




Thank you very much for this post – it’s solved a very big problem for me!
A minor typo: in Step 2 “sudo” should be added before “postmap /etc/postfix/sasl_passwd”
Best regards,
Mikkel
Thanks for catching it. Glad it helped!
hello,
Hope it work for me too because i really need it.
Thanks for this post.
This was fantastic! Thank you so much!
Thanks a lot,
thanks++
Thanks, This is working well.
Sadly, gmail seems to be refusing my tls connection:
my-macbook-pro:serp dball$ mailq
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
C41B3C100D0 378 Thu Sep 17 13:16:48 dball@my-macbook-pro.local
(TLS is required, but was not offered by host alt4.gmail-smtp-in.l.google.com[209.85.135.114])
my.username@gmail.com
– 0 Kbytes in 1 Request.
Any suggestions?
This worked brilliantly for me once I removed the underscores from your “_postfix” and “_postdrop” in the following main.conf lines. Were these just typos, or are they required in some cases?
# Minimum Postfix-specific configurations.
mydomain_fallback = localhost
mail_owner = postfix
setgid_group = postdrop
relayhost=smtp.gmail.com:587
Similar problem to dob, but no TLS issue. Simply:
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
8F5E52690185F* 317 Thu Oct 8 11:51:37 yaniv@beethoven.localhost
myname@me.com
I *can* access smtp.gmail.com on port 587 with telnet, and interact with the SMTP server there; nothing is blocking the path.
Ideas?
Thank you very much for this explanation! Spent around 2 days trying to get it working but your guide done it is just 3 mins
Thanks Man. I got it working for weeks but suddenly I am receiving this error.
(delivery temporarily suspended: Host or domain name not found. Name service error for name=smtp.gmail.com type=MX: Host not found, try again)
I didn’t do anything…once I got it working what I do is just sudo postfix start and sudo postfix stop when I’m not using it. What could have happened?
Thanks.
Thanks.
Arvi, if you can’t resolve the domain, some things to check:
1) Is there a difference between the nameservers you are seeing in /etc/resolv.conf and what appears in System Preferences > Network for the DNS Server? For that matter, /var/run/resolv.conf and /private/etc/resolv.conf should all match too.
2) Maybe it’s a problem with lookupd. You can restart it with “sudo dscacheutil -flushcache”.
3) Have you installed anything to block ports like PeerGuardian, Little Snitch or done anything firewallish?
4) Is the behavior different at home vs. school or a corporate network? Do you run your own DNS?
5) Anything else in /var/log/mail.log that looks interesting?