Setting Gmail as the Default Email Application in Linux

Date April 26, 2009 by Isaac

Yesterday I was searching for a way to make GMail my default email provider, so that when I click on "mailto" links GMail opens.  In Windows this is pretty easy, but I couldn't figure it out for Linux.  So, bring on Google search.  I found this web page which explains it succinctly.  While I don't run Ubuntu, the same method worked for Arch Linux.

Essentially:

  1. Go to System->Preferences->Preferred Applications
  2. For "Mail Reader" choose "Custom" and enter this (we'll create the script later):
    /home/username/bin/open_mailto.sh "%s"
  3. The above script will be triggered anytime you click on an email link.  Now, let's create the actual script.  Note: This is a modified script from the above web site.  It is based on some of the comments posted about the artice and then refined a little.  This script will properly handle subject, cc, to, body, and most any proper email tag that you can throw at it.  One other difference is that it can handle parenthesis.
    #!/bin/sh
    uri=`echo "$1"| sed -e 's/subject=/su=/' \
         -e 's/^mailto:\([^&?]\+\)[?&]\?\(.*\)$/\1\&\2/' \
         -e 's/(/%28/g' -e 's/)/%29/g'`
    firefox -remote "openurl(https://mail.google.com/mail?\
    view=cm&tf=0&to=$uri,new-tab)"
  4. Finally, change the mode of the script so that it can execute:
    chmod 755 /home/username/bin/open_mailto.sh

Hopefully that will work for you without problems.  In my tests so far it has worked great.

Comments are closed.