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!

Airfoil FTW

airfoil-mac@2x.png

Not sure how I missed out on this, but I Just discovered Airfoil for OSX and the companion iOS app Airfoil Speakers. This is a pretty fantastic app duo, allowing me to stream music from my Mac to an old unused iPhone which is connected to the stereo in my office without a physical connection. The audio quality is very nice, with only a second or so delay from the time that I change tracks, pause, etc.

Screen Shot 2015-11-11 at 3.11.09 PM.png

Making Colloquy IRC logs more friendly

If you’ve ever logged anything in “human readable” format from the OSX IRC client Colloquy, you’re probably used to seeing the logfiles in XML format, similar to this:

(click here for a more readable format)

  <event id="XXXXXXXXXXX" name="memberNewNickname" occurred="2013-01-02 12:00:00 -0500">
    <message>user1 is now known as <span class="member">user1|afk</span>.</message>
    <old>user1</old>
    <who hostmask="user1@X">user1</who>
  </event>

Not bad when there’s only a few entries, but with multiple logfiles containing thousands of entries each, it can chew up time and eat away at system resources. Wouldn’t it be nice if it looked more like this?

[12:00pm] user1 is now known as user1|afk.

Well, tonight I needed to go back and look for something in an old log, and parsing through the format of the log made it difficult to do with a simple grep command (note: I said simple). After some poking around I ran across a pretty simple, yet elegant solution: xsltproc.

From the project description: “It takes as first argument the path or URL to an XSLT stylesheet, the next arguments are filenames or URIs of the inputs to be processed. The output of the processing is redirected on the standard output.“. Yep, that’s what we need.

I found a pretty good PlainText.xsl file in a Google cache copy of a defunct add-ons page for Colloquy (it could use some improvements though, it only displays the time – no date. I’ll work on that), you can grab it here.

xsltproc /path/to/PlainText.xsl /path/to/channel.colloquyTranscript

The result? A nicely displayed logfile.

Happy Parsing.