OSX / Using Google Apps as a SMTP server

Scenario: You’re working from a home ISP connection or traveling, but would like to have your Mac send emails for jobs that have completed or other misc. notices without having to reconfigure each time. Since many ISPs block outbound SMTP servers on standard ports, forcing you to use their servers, this can be a headache.

I decided to use Google’s App/SMTP server to get around this as it uses a non-standard SMTP port and requires authentication. There are tons of guides on how to do this online, but none of them seemed to work for my setup. So, without further ado, here’s how to setup your mac, leveraging Google servers as a relay via Postfix:

First edit /etc/postfix/main.cf:

$ sudo vi /etc/postfix/main.cf

Add this to the end of the file:

myhostname = _HOSTNAME_
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtp_sasl_mechanism_filter = plain

Also, edit this line and adjust it to your preference, default is 1MB. I changed mine to 100MB since I send large logfiles:

message_size_limit = 100000000

Edit/create /etc/postfix/sasl_passwd. You’ll need to login to your Google account and create an app password. Spaces from this password are not required in this file:

$ sudo vi/etc/postfix/sasl_passwd

The format of the file should look like this:

[smtp.gmail.com]:587 user@domain:app_password

Modify the permissions of the password file to protect the contents:

$ sudo chmod 600 /etc/postfix/sasl_passwd

Next, hash the password. This will create a sasl_passwd.db file:

$ sudo postmap /etc/postfix/sasl_passwd

Restart the postfix services for the change to take effect:

$ sudo launchctl stop org.postfix.master
$ sudo launchctl start org.postfix.master

And finally, run a test:

$ date | mail -s "test 1 again” you@yourdomain.com

Check the queue for errors. Should report “Mail queue is empty” if everything went well.

$ date && postqueue -p

If you received the message, then you’re all set. Your OS can now send mail from anywhere in the world without having to worry about reconfiguring for local SMTP servers due to blocked ports.

Happy mailing!

A little wp.com love

Why yes, I did notice that somehow all the default homepages in the computer room of the hotel I’m staying in this evening were set for WordPress.com. Wish that that engineering soul had brought some WP stickers to put on top of the Microsoft logo hanging on the wall.

Someone should probably do this every time we’re at a meetup or on travel. 🙂

Harborfest 2016

Spent the day at Harborfest with the kiddo, this is the 40th anniversary of the event which is “America’s largest, longest-running, free maritime festival“. The weather was beautiful, the mercury was high, and sunburn aplenty. Got to see a lot of really neat ships, booths, performances, and demonstrations. The food was pretty fantastic too! 🙂