I spotted this article describing how to make Ubuntu send mailto: links through Gmail. It’s not wrong exactly, but I wanted to improve upon it a little. I have my own version which requires no external files, and all it needs is that you send your mailto: links through this command…

sh -c "firefox 'https://mail.google.com/mail?view=cm&tf=0&to='$(echo "$1" | sed -e 's/mailto:(//)?//' -e 's/?/&/' -e 's/&subject=/&su=/I')" custom-mailto-launcher "%s"

On Ubuntu, go to System -> Preferences -> Preferred Applications, change your mail reader to “Custom”, then put this line in. If you use another version of Linux, you’ll have to figure that part out yourself. Keep in mind %s is the variable and firefox is the default browser in my example.

Mine removes the “mailto” part a little better, and makes a hacky attempt to parse the subject/cc/bcc arguments these links sometimes have. Most importantly though, it’s a one-step process.

5 Responses to “Make Gmail Handle Your mailto: links in Linux”

  1. Soulfreshner Says:

    This is a great tip. You need to url encode the links though, otherwise firefox gets all kinds of cranky when it gets spaces and such. I just replaced spaces with %20 and haven’t had a problem yet – would not bet my head that it won’t break somewhere else, though:

    sh -c “firefox ‘https://mail.google.com/mail?view=cm&tf=0&to=’$(echo “$1″ | sed -e ‘s/mailto:(//)?//’ -e ‘s/?/&/’ -e ‘s/ /%20/g’ -e ‘s/&subject=/&su=/I’)” custom-mailto-launcher “%s”

    good job with this hack!

  2. Giovanni Says:

    Super! It works great, thank you!!

  3. eddieW Says:

    This is great, and works with one slight issue: gmail inserts a “/” in front of the email address, making it undeliverable. I’ve tried, by process of elimination – trial and error – to get rid of this, but it either inserts the “/” or leaves the email address out entirely. If it helps, I’m trying to insert the email address using gnome do. Thanks.

  4. Ian Says:

    To eddie, or anyone else who stumbles onto this post:

    For gnome do, it’s simple: replace this:

    sed -e ’s/mailto:(//)?//’

    With this:

    sed -e ’s/mailto:(/)+//’

    And it’ll do what you want.

  5. Lobotomik Says:

    How do you do this in Precise? They’ve dumbed it down further, so there is no ‘custom’ entry in the Preferred Applications, which BTW has been hidden away in System-Tools/System-Configuration/Details/Preconfigured-Applications, and has entries only for web, mail, calendar, music and photos.

Leave a Reply