Friday, October 02, 2009

Tidbit: Using GMail as your default email client

I mostly use GMail for email purposes and so it makes sense to make it my default email client. There are many ways to do this on the web. However, most are desktop environment or browser specific. It is nice to have things behave similarly across desktop environments or even installations. So I threw together a quick bash script that would use the default browser that is configured for your system. Here it is.


getopen () {

if [ -x /usr/bin/xdg-open ]
export opener="/usr/bin/xdg-open"
elif [ -x /usr/bin/kde-open ]
export opener="/usr/bin/kde-open"
elif [ -x /usr/bin/gnome-open ]
export opener="/usr/bin/gnome-open"
echo "Requires xdg-open, kde-open or gnome-open"
exit 1

getemail () {

export address=`echo $1 | sed 's/mailto://'`
export targeturl="$address"

getemail $1
exec $opener $targeturl
exit 0

Save this in a file. I called mine gmailer and saved it to ~/bin. Make sure it is executable and that your system is configured to search ~/bin for executable commands. Now configure your system to open mailto: links with gmailer. That would be gmailer %s in Gnome/XFCE and gmailer %t in KDE4. Cool thing is that gmailer run from command line or the Ctr+F2 launcher works just as well!

There is a limitation to it. If you are not already logged into GMail or your browser does not automatically log you in, it will not work. It surely can be better but it works just fine for me right now. Obviously, suggestions are most welcome! Enjoy!

[EDIT] Want to do this with Yahoo Mail instead? Click here.


jason said...

Why not just configure Thunderbird to your gmail account, seems alot easier and as long as you have a internet connection your connected.

Shane said...

That could be an option. But I use Firefox with Google Gears installed and offline GMail enabled.

This means I get the full 'GMail exeprience' including GTalk (with history), Labels and search available all in one place... even offline (except for chat of course). Besides, I think the GMail interface is the best email UI I have ever used - web based or local.

Anonymous said...

This was exactly what I was looking for! Thanks! I am going to see if I can figure out how to adapt it to open up a new chrome tab, instead of a separate window. If I do, I will post it here. --pghpete

Anonymous said...

Scratch that last post! If you have the latest chrome (as of post time) and Fedora 13, it automatically opened another tab instead of a new browser instance. Sweet. --pghpete

Shane said...

Thanks for posting back. I tested it with Chrome just now and it opened in a new tab. I thought I had some setting enabled...

Glad it helped you :)

frodeseverin said...
This comment has been removed by the author.
frodeseverin said...

Note to self: Always remember to preview posts.

Just thought I should help out with the problem with not being logged in prior to using the script.

According to
the correct URL format for giving GMail a mailto: link is

This works like a snap, and I have tested it withoyt being logged in. Sweet.

I changed you script to look like this.

getemail () {

export targeturl="$1"


Now, my only trouble is to get xdg-open to prefer Chromium over Chrome.