Mike's stuff‎ > ‎

Set Gmail as default mail client using Google Apps in Linux

posted 25 Jan 2010, 22:19 by Michael Strand   [ updated 12 Jun 2010, 17:16 ]
You can have Google Apps as your default mail client in Linux.

First install gnome-gmail from here http://gnome-gmail.sourceforge.net/. This installs a Python script, /usr/bin/gnome-gmail. You can then go to "System > Preferences > Preferred Applications" and set gnome-gmail as your custom mail application.

*** UPDATE: Editing the script is no longer required *** Just install as set as the preferred mail app. Then logout and log back in and go to Applications > Configuration Editor and in the apps tree expand gnome-gmail. All you have to do is set your apps domain here.

This script is configured for Gmail not Google Apps but it is easy to change. Open /usr/bin/gnome-gmail with your text editor and there are three URL references to Gmail that we will change.


import sys
import urlparse
import gio
import string

def appendUrl( tourl, urltag, dict, dicttag ):
tourl = tourl + "&" + urltag + "=" + dict[dicttag][0]

return tourl

# get the path string from the 'possible' mailto url
usplit = urlparse.urlsplit( sys.argv[1], "mailto" )
except IndexError:
# couldn't even get an email address - just open a default mail page
gio.app_info_get_default_for_type( "text/html", 1 ).launch_uris( ["http://mail.yourdomain.com"] )
sys.exit( 0 )

path = usplit.path

# for some reason, urlsplit is not splitting off the query string
# do it here
( address, qs ) = string.split( path, "?", 1 )
except ValueError:
address = path
qs = usplit.query

qsdict = urlparse.parse_qs( qs )
qsdict['to'] = []
qsdict['to'].append( address )

tourl = "https://mail.google.com/a/yourdomain.com?view=cm&cmid=0&fs=1&tearoff=1"
tourl = "https://mail.google.com/a/yourdomain.com?view=cm&tf=0&fs=1"

tourl = appendUrl( tourl, "to", qsdict, "to" )
tourl = appendUrl( tourl, "su", qsdict, "subject" )
tourl = appendUrl( tourl, "body", qsdict, "body" )
tourl = appendUrl( tourl, "cc", qsdict, "cc" )
tourl = appendUrl( tourl, "bcc", qsdict, "bcc" )

print tourl

gio.app_info_get_default_for_type( "text/html", 1 ).launch_uris( [tourl] )

When you are in Google Mail check your URL and compare it to the URLs in the script, if your URLs are slightly different you can change the script to match your Google Apps mail URL.