choosing smtp servers for selected accounts in with location sensing

A problem I’ve been having is that everywhere I go I need to change the SMTP server settings for my personal and consulting accounts. The GMail IMAP accounts have authenticated SMTP and they work great everywhere, but for my personal IMAP accounts, I use the SMTP server provided by my ISP as I don’t want to set up authenticated SMTP over SSL or POP/IMAP before SMTP on my server and I definitely don’t want to run an open relay.

To solve this, I found Marco Polo, with it you can define a set of Contexts, which could be something like Office, Home, or anything else. You then define a set of Rules to figure out which Context you’re in based on Evidence Sources such as the mac address or SSID of the wireless access point you’re connected to, presence of Bluetooth/USB keyboard/mouse, external monitor, ethernet cable plugged in or unplugged, etc. Base on these you can setup rules

Here are screenshots of my setup:


Evidence sources:


Once you have these setup it will guess where you’re at based with a confidence score, and you can trigger Actions on entering or leaving a Context.

Here are my actions to set SMTP servers:

Notice the first 3 MailSMTPServer actions were disabled, this is because that action actually changes the smtp server of ALL your accounts in I have 2 GMail over IMAP accounts (GApps for domains) and I want to use GMail’s authenticated SMTP server for those because they manage your sent mail properly when you do that. There is a “User only this server” checkbox in Leopard’s but that doesn’t prevent the MailSMTPServer action from changing it!
So to get what I want, which is to only set the SMTP server for my personal and consulting accounts, I had to do a little bit of scripting, I like Ruby so I write a rb-appscript like this:

#!/usr/bin/env ruby
begin; require 'rubygems'; rescue LoadError; end
require "appscript"
include Appscript
['Personal', 'Consulting'].each do |account_name|
  #tell application "Mail" to set smtp server of account_name to argv[0]

Marco Polo however can only execute shell scripts, so I had to compile the script into a Mac application to use the Open action in Marco Polo. To do that I had to write a shell script for each SMTP, something like this:

/Users/ayn/bin/setSMTP.rb comcast

To make this script into an OS X application, I used Platypus:

It didn’t work at first, I ran it with error outputs and turned out the Ruby library wasn’t setup correctly, so to get it working I had to go add the path for Ruby:

Now you can compile the shell script, which calls the ruby script with an argument, into a Mac application. In Marco Polo you can then use the Open action to call that .app.
Kindda a long way to do something relatively simple, I wish the “Use only this server” account option in actually works as expected.

No comments yet.

Leave a Reply