Set Gmail as Default Mail Client in Ubuntu
Every Geek uses Gmail… it’s pretty much required. And now you can set Gmail as the default client in Ubuntu without any extra software. (Windows requires the Gmail notifier be installed)
Just go to System \ Preferences \ Preferred Applications
Under Mail Reader, select Custom, and then put this into the Command window, changing “geek” to your username.
/home/geek/open_mailto.sh %s
Next, you’ll need to save this shell script into your user directory ( /home/username ). [Download]
For the curious, here’s the contents of the script:
#!/bin/sh
firefox https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed ’s/mailto://’`
If you’d like to make the script open a new tab in an existing Firefox window, you can replace the firefox line in the script with the following:
firefox -remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed ’s/mailto://’`,new-tab)”
Update: If you want to make the script file hidden by default, you can rename it with a . at the beginning of the file like this: .open_mailto.sh. You’ll have to change the path in the preferences, of course.
Open a terminal and type in the following command, to make the script executable:
chmod u+x ~/open_mailto.sh
Now it should be working.
To test it out… I clicked the contact link on my page… and it immediately opened in Gmail.
Note that if you aren’t logged into Gmail you’ll be prompted to login to gmail… and you’ll have to click the email link again. Seems like Gmail’s login redirector won’t open the send mail page. But then again… why aren’t you logged into Gmail?
Update: Changed to point to a script so that the mailto: tag would be removed. Thanks VERY much to Mr Linux for not just noticing, but giving me the working script.
Daily Email Updates
You can get our how-to articles in your inbox each day for free. Just enter your name and email below:
| Similar Articles | Featured Wiki Articles |
| Latest Software Reviews | Quick Linux Tips |
| Geek Arcade | Popular Forum Threads |


Using the first command works just fine, although clicking on your contact link gives me the following email address in the to field: “mailto:geek@howtogeek.com” (without the “”). Any suggestions?
The second link doesn’t work for me.
-Henriette
Nice hack! I put a link to it on my site!
Pretty sweet article! Actually, when I click on the the “Contact the geek” link, I get a new GMail “Compose Mail” page with the To: field set as “mailto:geek@howtogeek.com”. Any idea why this would be?
It’s probably possible to strip out the “mailto:” using sed but I’m too lazy to write a regexp right now.
Very nice. Thanks for sharing.
Great tip! This more or less works with any OS–I got it working in Gentoo, with no tweaking of the script (just different menus). Awesome.
this script works for pretty much all linux distros using gnome, not just ubuntu.
Is there anyway to do this within Firefox (Windows) itself? Like when I click a mailto link in Firefox it opens in Gmail rather than my email client at work?
Vince
Make sure you have %s at the end of the custom mail command otherwise it won’t pass the email address.
Jonathan,
Thanks for noticing the typo! Updated article.
Very useful how-to. Thx for sharing.
Finally! A fruitful and productive use for sed…
this is great
This doesn’t quite work for Kubuntu (and KDE). Instead, find the equivalent settings page (for Kubuntu – System Settings / Default Applications / Email Client) and enter this:
/home/geek/open_mailto.sh %t
Note the %t instead of %s. Where /home/geek/open_mailto.sh is the same as above. Make sure you remember to chmod u+x ~/open_mailto.sh
This will work perfectly for links clicked in KDE applications, but Firefox still needs to be tweaked. Follow these directions:
http://gentoo-wiki.com/HOWTO_I.....ent:_KMail
But instead of kmail, use the full path to the script (/home/geek/open_mailto.sh). Enjoy!
@Vince
I suggest you use the GMail Notifier. It will allow you to intercept the mailto: calls on Windows and redirect them to gmail. There’s a bit of flakiness with Vista though because to change the default actions requires user elevation.
@Dan,
Thanks! That’s great stuff. I’ll update the article later with it.
Might I suggest that the script be named so that it is a hidden file. I don’t like anything showing in my home user directory by default other than my data directories (music, photos, documents, torrents, videos, etc.). Simply add a period at the beginning of the script name so that is becomes…
.open_mailto.sh
*Remember to make this change wherever the script is called in the instructions above!
I want an identicon
Hi there i used this hack i am able to access the gmail only when there is mailto:…… other wise is it looping the compose is not opening ..for example i am browsing craig listing and when i click on the email adress there i am not able to open the compose but it is looping …the gmail pages is just loading thats it can u add or fix this problem ur help will be appreciated
I had to replace the ‘ with ” in ubuntu. So my command is:
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed “s/mailto://”`”
sed complained:
sed: -e expression #1, char 1: unknown command: `
when the “s were ’s
Thanks for this incredibly useful tip. I hate client-side mail apps.
@ Vince, Mr.Linux
To add default mailto: handler in Windows, look at:
http://msdn2.microsoft.com/en-.....53633.aspx
thanks for this – great article.
Briliiant stuff thanks!
This is ABSOLUTELY fantastic! Thank You very much
I get the same looping when I click on a contact link on craigslist as wel. Hmmmmmm…. I wonder what’s going on here?
works great. i love this blog. thanks!
At first this script did not work for me, I was getting this:
sed: -e expression #1, char 1: unknown command: `
So I took out the ” ‘ ”
Slight modification:
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed s/mailto://`”
You can even run the script from the command line: ./open_mailto.sh someone@email.com
Nice hack!
~~RK
As soon as this option was available (couple of months ago or so), I did it in Firefox and Flock on Windows XP. I really run away from those pop-up emails opening Outlook (opens sooo slow), and I prefere Gmail over it, anyway. (Ever since I started emailing, 10 yrs+, I have rarely used Outlook, but usually read everything right from the server – with all those viruses, etc., such practice saved me more times I can count.)
Works great in Mephis. Excellent idea to hide the script via .open_mailto.sh
You forgot the subject line
for example:
mailto:you@host.com?subject=Hello world
I’m not too good at bash programming but here is my modifications but working with yahoo!
#!/bin/sh
qs=`echo $1 | sed ’s/mailto:/To=/’ | sed ’s/\?subject=/\&Subject=/’`
firefox “http://compose.mail.yahoo.com/?$qs”
To hide the file, you can also make a .hidden file in your home directory and put the files name in there, like this:
$ touch .hidden
$ echo “open_mailto.sh” >> .hidden
You can add other filenames to the .hidden file (and also directories) separating them with a newline.
optimization (without sed):
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&to=${1/mailto:/}”
Great How-To! Now let’s set gmail to the default in Opera. (Yay Opera!)
#!/bin/sh
# system \ Pref \ Pref App -> ~/bin/gmailto "%s"
# (IN OPERA) Tools \ Preferences \ Programs \ mailto \ Open with Other App "~/bin/gmailto"
opera -newpage "https://mail.google.com/mail/?view=cm&tf=0&to=`echo $1 | sed "s/mailto://"`"
Nice tip. Traditionally, such a script would be placed into ~/bin (and the corresponding path name used in the pref box of course).
Thanks for the very handy instructions. I use Google Apps for my Domain and had to modify the script a little to get it to work. I have posted instructions on my site. (http://www.atomeo.com/2007/05/.....n-ubuntu/)
Worked for me first try……….thanks a bunch!
Cutting-and-pasting the script does not quite work for me, and it is almost certainly a character encoding issue.
Me:
Ubuntu 6.06LTS
Firefox 1.5.0.11
Character Encoding for this page detected as UTF-8
The “single quotes” in the code on this page are not *really* single quotes, they are Unicode right and left single quote marks, ‘ and ’ Take a look at the source code of this page! (see http://www.pemberley.com/janeinfo/latin1.html for example)
I had to chagne everything to the actual straight single quote for the script to work, else sed gave an error:
sed: -e expression #1, char 1: unknown command: `
Later…
The suggestions for kde are great. They worked perfect except for Firefox, but that was easy too.
about:config
create-> new string
network.protocol-handler.app.mailto /home/geek/open_mailto.sh
good to go, and thanks for the script!!
Here’s my script:
#!/bin/sh
gmailargs=`echo $1 | sed ’s/mailto:/to=/’ | sed ’s/\?subject=/\&su=/’ | sed ’s/\?cc=/\&cc=/’ | sed ’s/\?bcc=/\&bcc=/’ | sed ’s/\?body=/\&body=/’`
/opt/firefox/firefox -remote “openurl( https://mail.google.com/mail?view=cm&$gmailargs, new-tab )”
I think it covers the entirety of mailto: possibilities. Thank you http://www.ianr.unl.edu/internet/mailto.html.
Woa, there David! A few too many seds in a row. Try this one instead.
#!/bin/sh
#when we are passed an email address like this:
#mailto:vdog@domain.com?subject=hi%20vernon&body=please%20unsubscribe%20me%20from%20this%20mad%20list&cc=mad@max.com&bcc=jo@mama.com
#we want to generate a uri like this:
#http://mail.google.com/mail/?view=cm&tf=0&to=vdog@domain.com&cc=mad@max.com&bcc=jo@mama.com&su=hi%20vernon&body=please%20unsubscribe%20me%20from%20this%20mad%20list&zx=9i09cu-h33iui
# remove the ? from the uri
uri=`echo “$1″ | sed -e ’s/subject=/su=/’ -e ’s/^mailto:\([^&?]\+\)[?&]\?\(.*\)$/\1\&\2/’`
firefox “https://mail.google.com/mail?view=cm&tf=0&to=$uri”
Hey, this is awesome thanks!
Just wondering though, When I use the script, gmail pops up perfectly right in the compose area, but it doesn’t fill in the email address! So basically all the script does is launch gmail. I am using Ubuntu feisty and the script that opens gmail in a new tab in firefox. Could you please help me?
I’m having the exact same error as dfreer.
Are you clicking on a mailto: URI to launch gmail in this way? Or is this something in an application somewhere? For most applications (like Terminal), Gnome will change an email address link into a standard mailto: form (for app compatibility). It’s possible that the script just isn’t able to parse whatever form the particular app you’re using is generating. In that case, it certainly wouldn’t be able to fill in the address.
I try clicking on an html mailto: form, like this one.
somebody@somewhere.com
the code looks like this (only with brackets):
a href=”mailto:somebody@somewhere.com” somebody@somewhere.com
here’s my open_mailto.sh script (note, everything else works fine it just doesn’t put the email address in the gmail form):
[CODE]
#!/bin/sh
# This script, when set as default mail handler in
# System > Preferences > Preferred Applications
# Will use gmail as the mail client!
firefox -remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed ’s/mailto://’`,new-tab)”
[/CODE]
Hi, again. A simple addition to the script to make it work with Firefox’s “File->Send Link” functionality:
#!/bin/sh
FIREFOX=`which firefox`
TO=`echo $1 | sed ’s/mailto://’`
## Next 4 lines let you send link from Firefox
SENDLINK=`echo $TO | grep ‘body’`
if [ $SENDLINK ] ; then
TO=`echo $TO | sed -e ’s/?/\&/g’`
fi
$FIREFOX “https://mail.google.com/mail?view=cm&tf=0&to=$TO”
Having the same problem as dfreer using Ubuntu feisty and firefox 2.0.0.4. Everything works except email addr does not appear in “To:” line.
Keep it short and sweet, people.
#!/bin/sh
FIREFOX=$(which firefox)
URL=$(echo $1 | sed ’s#mailto:##;s#?#\&#;s#\&subject=#\&su=#i;’)
$FIREFOX -remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=$URL)”
Same problems as others noting using Firefox and Fiesty, but I come bearing the tasty treat of more info:
the script (in almost all its variations) works when passed a sample email address in the console, but when you click on a mailto in firefox, the script never seems to get the address. In other words, clicking on a mailto for someone@example.com yields [https://mail.google.com/mail/?view=cm&tf=0&to=&fs=1] in the address bar. The console command [./open_mailto.sh someone@example.com] yields a result of [https://mail.google.com/mail/?view=cm&tf=0&to=someone@example.com&fs=1]
My best guess is that, in Fiesty, this information is being passed differently than it has been, and the script is no longer picking up the mailto info the way it should. Will update if I manage to create a workaround for this.
OK, so…found the solution, and it turned out to be almost painfully simple. In Feisty, you need your command line entry to read as follows:
/home/geek/open_mailto.sh %s
The %s tells Feisty to pass the mailto link along to the shell script, without it there it doesn’t feed the script any parameters whatsoever, hence the problem.
Mike,
Thanks for that… typo in the article…
right mouseclick > send link, doesn’t work
Thanks mike, that fixed the problem! it works great now.
For those who are finding the email address is not put in the composition window, there needs to be an escape character in front of the ampersand in the shell script:
firefox https://mail.google.com/mail?view=cm\&tf=0\&to=`echo $1 | sed ’s/mailto://’`
YAHOO!
I use fedora, but I think the instructions are the same regardless. I edited Jeff Waugh’s instructions above for yahoo.com (thanks Jeff!):
#!/bin/sh
FIREFOX=$(which firefox)
URL=$(echo $1 | sed ’s#mailto:##;s#?#\&#;s#\&subject=#\&Subj=#;s#(##;s#)##i;’)
$FIREFOX -remote “openurl(http://us.f368.mail.yahoo.com/ym/Compose?To=$URL)”
Note that I stripped the “(” and “)” characters. They were not working for some reason, and are in all of the craigslist listings.
Also note that the yahoo site address might be different for you in your area.
brilliant, concise, short, and effective. awesome, very helpful. thanks for perpetuating the geekdom! by the way, out of curiosity,in what language is the succinct script written.? thanks
Using Feisty with FF 2.0.0.5, the first script does not work unless double quotes are added around the URL, like so:
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed ’s/mailto://’`”
super-freaking-cool. Thanks.
Any way this command can simply be executed from the Preferred Applications utility, rather than calling a script?
concise, effective and very easy to use. thanks!
Strange, I can’t get it to work properly. In FF I had to create a string named network.protocol-handler.app.mailto with a value of /home/geek/open_mailto.sh %s to make it load from FF. Then I had to escape the ampersand as Nigel suggested, to parse the mail adress. OK, now it works from FF, and as it’s my main browser that’s good.
But when clicking a mail link in Konqueror, the mail adress is missing… with or without the escape sign in the script.
I’m trying Gutsy Tribe 4, is that the problem maybe? I noticed there is some problem with the system setting utility writing two $ signs, like $$HOME (it automatically rewrites the full path), sometimes if you edit the path to the script, but as long as you double-check it you’ll be safe from that error.
Any suggestions?
I just did the one by Dhonn (on May 10, 2007 7:42 pm ) and after i removed the quotes it worked perfectly for yahoo!
Thanks so much man, i really needed this feature!!
I’ve adapted the script above by Vernon Mauery so that it works with the “Send Link” in Firefox. I’m sure it could be done with one fewer statements to sed, but I’m too lazy to work it out
This is with Firefox 2.0.6 on Ubuntu 7.04 by the way.
Here’s hoping that the form doesn’t do anything screwy to the code below…
#!/bin/sh
#when we are passed an email address like this:
#mailto:vdog@domain.com?subject=hi%20vernon&body=please%20unsubscribe%20me%20from%20this%20mad%20list&cc=mad@max.com&bcc=jo@mama.com
#we want to generate a uri like this:
#http://mail.google.com/mail/?view=cm&tf=0&to=vdog@domain.com&cc=mad@max.com&bcc=jo@mama.com&su=hi%20vernon&body=please%20unsubscribe%20me%20from%20this%20mad%20list&zx=9i09cu-h33iui
# The first sed changes ’subject’ to ’su’ (gmail uses su instead)
# The second sed removes the ‘mailto:’ from a standard mailto:bob@foo.bar
# The third sed is described below
#
# When we get something a link from Firefox (others?) that is a “Send Link”, it comes as
# mailto:?body=http%3A%2F%2Ffoo.bar
# Which we want to turn into
# &body=http%3A%2F%2Ffoo.bar
#Script adapted from post http://www.howtogeek.com/howto.....ment-16706
# by Vernon Mauery
URI=`echo “$1″ | sed -e ’s/subject=/su=/’ -e ’s/^mailto:\([^&?]\+\)[?&]\?\(.*\)$/\1\&\2/’ -e ’s/^mailto:[?]\(.*\)$/\&\1/’`
firefox “https://mail.google.com/mail?view=cm&tf=0&to=$URI”
Thanks for the subject fix Chris!
But none of the suggestions here can make it work from both firefox and konqueror?
great little hack love it and easy to do.
@Chris
Nice fix… I had a little problem with it
I had to change,
URI=`echo “$1″ | sed…
to
URI=`echo $1 | sed…
the quotes messed it up I guess
I’m running Ubuntu 7.04 Feisty
Thanks all
Nice – watch out when copying & pasting these links, sometimes you’ll find double quotes changed to special ‘backwards double’ quotes. Happened to me & sounds like it happened to Jim above.
Thanks to all!
I think this is the best (based on JDS’s script):
#!/bin/sh
ARGS=`echo $1 | sed ’s/mailto://’`
## Next 4 lines let you send link from Firefox
SENDLINK=`echo $ARGS | grep ‘body’`
if [ $SENDLINK ] ; then
ARGS=`echo $ARGS | sed -e ’s/?/\&/g’`
fi
firefox -remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=$ARGS,new-tab)”
place it in /usr/local/bin
you have to create it as root with sudo gedit open_mailto.sh (or similar)
then use this command: chmod a+x filepath
Nice. works fine. but i want to twist a litle more, so i was thinking about a script that sends a selected archive (with thunar – User Customizable Actions see thunar page for more details) via gmail. tried to use this script and noticed that i could just copy the filepath that apeared in the “to” box. so my question is
¿how can i modifiy the script so that it pastes the direction as a attached file or files?
thanks.
If you want it to whatever your default browser is (firefox, konqueror, epiphany, etc) download and install xdg-utils and then replace firefox in the script with xdg-open and it will automatically use your default browser.
mine works when i execute the script from a terminal, but when i click a mailto: link, it does not launch firefox.
any suggestions?
Hi,
on gutsy al leats this won’t work this way as the & in the script is interpreted by the shell. Here’s a working version:
#!/bin/sh
gnome-open https://mail.google.com/mail?view=cm\&tf=0\&to=`echo $1 | sed ’s/mailto://’`
note that “gnome-open” makes it use your preferred browser instead of hardcoding firefox.
Cheers,
Karel Demeyer.
is there anything we can’t do w/ ubuntu?:> I love how greatly customizable it is!
> is there anything we can’t do w/ ubuntu?
Get any real work done…
Thank you very much, that’s what I was looking for, for a very long time.
double thumbs up
anyone got this message from gmail:
mail.google.com has sent and incorrect or unexpected message. Error Code: -12263
whatever script is used?
Thank you, this is extremely nice. I saw this (in a round-about fashion) from lifehacker, I hope they update to link your site.
Cool stuff.
Actually, though real geeks access Gmail via IMAP and Mutt
Hi,
I define
about:config
create-> new string
network.protocol-handler.app.mailto /home/geek/open_mailto.sh
now if i click mailto from firefox I get the expected behavior (gmail compose);
however, if i click on an html file in the nautilus, i get the “choose session” dialog for firefox (I have two sessions); does anyone know how I can tell (ubuntu, gnome, nautilus, whomever) that when i click
on a local html file, simply open it in the current session in a new tab?
many thanks
les
I guess you can write a script and all that, or just in the custom slot put
firefox -new-tab https://mail.google.com/mail?view=cm&tf=0&to=
my accuont has been disabled. pls help me to log to dat same id , thank you
Thanks for the script.
It works fine for simple mailto: links but for others, the page with gmail keeps loading.
For exmaple, from this page: http://www.e-sante.be/magazine.....p;urlnew=0, I clicked on “J’envoie cet article à un ami” to send the article to a friend. Firefox opens a new tab with Gmail, but nothing is displayed and then page is also switching between “Loading gmail” and “Waiting for Gmail”
The mailto: link is “mailto:?body=Bonjour,%0D%0A%0D%0AVoici un article int%C3%A9ressant trouv%C3%A9 sur e-sante.be :%0D%0A%0D%0Ahttp://www.e-sante.be/be/magazine_sante/femmes_leur_sante/acne_post_adolescente_essentiellement_feminine-7416-950-art.htm%0D%0A%0D%0ATr%C3%A8s bonne lecture et %C3%A0 bient%C3%B4t !%0D%0A%0D%0Ae-sante.be, votre magazine forme et sant%C3%A9.%0D%0A%0D%0ARecevez chaque semaine la newsletter e-sant%C3%A9 avec ses nombreux articles forme et sant%C3%A9, ses recettes minceur, son test de la semaine et ses forums.%0D%0A%0D%0APour vous abonner gratuitement, cliquez ci-dessous :%0D%0A%0D%0Ahttp://www.e-sante.be/be/magazine_sante/newsletter_inscription.htm%0D%0A%0D%0A%0D%0A%0D%0Ahttp://www.e-sante.be&subject=Un article d’e-sante.be”
This doesn’t seem to be working for me. I get the following “We’re sorry, but your Gmail account is currently experiencing errors. You won’t be able to use your account while these errors last, but don’t worry, your account data and messages are safe. Our engineers are working to resolve this issue. Please try accessing your account again in a few minutes.” Anyone else have this problem. GMail works fine otherwise… just when I use this script I get this error.
Brian, I was getting the same error until I noticed that the second double quote on the line which starts with URI=`echo “$1″ is a smart quote. If you replace it with a normal double quote, it should work fine.
Then I looked back at the comments and saw that Jim Robert already posted that correction above.
I think the new Gmail version broke this script. Now the Compose URL is https://mail.google.com/mail/#compose and I’m not sure how to pass arguments to this format. Any ideas?
Hi. I really loved this script until it inexplicably stopped working. I guess Gmail changed something (cf. Phil’s 1/16 post). After some time looking around the web, I found “&ui=1″ sets the Gmail user interface to the “older” style. So I added that to the script and it now works again. Even though I’m logged into Gmail using the “newer” style interface for regular work.
New version (works for me – Ubuntu 7.10, Firefox 2.0.0.11):
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&ui=1&to=`echo $1 | sed ’s/mailto://’`”
Cheers!
Simple change will try to open tab and if that fails open new firefox:
#!/bin/sh
if [ "$1" ]; then
URL=”https://mail.google.com/mail?view=cm&tf=0&to=”`echo $1 | sed -e ’s/subject=/su=/’ -e ’s/^mailto:\([^&?]\+\)[?&]\?\(.*\)$/\1\&\2/’`
else
URL=”https://mail.google.com/mail”
fi
if ! firefox -remote “openurl(${URL}, new-tab)”; then
firefox ${URL}
fi
# EOF
Looks like Google changed things yet again. This line works for me, as of 30 Jan 2008:
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&ui=1&to=”`echo $1|sed -e ’s/?subject=/\&su=/’ -e ’s/mailto://’`
Fantastic! Thanks.
Really gr8 tip. And it (the main description) works fine for me!
Thx.
This worked for me with opera and slackware 12.0 (had to use %t, not %s in opera preferences for mailto).
This opens the gmail page in a new tab.
#!/bin/sh
opera –remote \
“openURL(https://mail.google.com/mail?view=cm&tf=0&to=${1/mailto:/},new-page)”
Opera in Ubuntu 7.10 Gutsy, the ${} didn’t work for me, so I just replaced it with the backticks version and it now opens a new tab.
swap in `echo $1 | sed s/mailto://` where ${1/mailto:/} goes looks like this
opera -remote \
“openURL(https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed s/mailto://`,new-page)”
Many thanks to the previous post, I didn’t know about the openURL method
Cheers
To the previous post. How about this: ${f##*:}? (instead of ${1/mailto:/}
#!/bin/sh
opera –remote \
“openURL(https://mail.google.com/mail?view=cm&tf=0&to=${1##*:},new-page)”
We don’t even need a separate file. Simply put this in the custom command field:
firefox “https://mail.google.com/mail?view=cm&tf=0&to=${%s/mailto:/}”
This works for me in Ubuntu 7.10, Firefox 2.0.0.12.
@ Andrew Cheong:
Hi Andrew your solution seems to work fine, when I click on a mailto: link I get a new Gmail composition window in a new tab; but the TO: field contains this “${mailto:geek@howtogeek.com/mailto:/}” instead of just the email address…. any idea how to correct this?
[Please ignore my previous comment. I made a mistake. Thanks Thomas!]
*************************
THE ONE-LINE SOLUTION!!!
*************************
If you have Perl installed, simply copy and paste this into the custom command field!
perl -e ‘q/%s/=~/^mailto:(.*)$/;`firefox “https://mail.google.com/mail?view=cm&tf=0&to=$1″`;’
This works for me in Ubuntu 7.10, Firefox 2.0.0.12, with Perl 5.8.8. I double-checked this time!
@xyz
your solution producedthe following error message in Opera. Please note I’m using the latest beta so that I can view Youtube in Opera on Ubuntu 7.10 Gutsy, so this may be related or not. For some reason it didn’t transcribe the http link as the openurl is in the URL.
“You tried to access the address http://openurl(https//mail.goo.....om….”
I’ll just say that what I have below works okay for me. YMMV it would appear!!
opera -remote \
“openURL(https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed s/mailto://`,new-page)”
@XYZ
scratch that. After testing this no longer works in Opera, neither your nor my version. I still get the openurl lingering in the URL. If you place the script in the system/prefs/preferred apps section however, the script does work in Firefox, in that it opens Opera (my default browser) and goes to the google mail page correctly. But it won’t work in Opera directly.
I’ll play around with it a bit more
@xyz
got it. I moved the parameter…to the parameter section *duh*. Switched the %s with %t because the email address was not appearing in the URL causing a gmail 404 error. With %t the email is now added. Now Opera forwards a mailto in gmail without a problem. *whew*.
tried it again with your non-echo version but it still puts the openurl into the URL. Went back to the script I mashed and it’s fine in both firefox and opera.
Sometimes I’d get an error with opera for some addresses (long ones?).
After fiddling a bit, this fixed the problem:
~/gmail/mailto.sh “%t”
(put quotes around %t)
This is quite handy, thanks!
*************************
THE ONE-LINE SOLUTION!!! *** UPDATED ***
************************* (now supports “?subject=”)
perl -e ‘q/%s/=~/^mailto:(.*?)(?:\?subject=(.*))?$/;`firefox “https://mail.google.com/mail?view=cm&tf=0&to=$1&su=$2″`;’
excellent, i had to change the browser to swiftfox cause thats what i use, but really good stuff just the same
Thank you very much!!!!!!!!!!!!!
Here’s a version that will handle “Send Link” as well as mailto URLs…..
http://dcc.vu/ubuntu-linux-fil.....gmail.html
this is awesome. thanks a ton, man!
this worked fine in gutsy…a bit different in hardy though….i can’t get it to work again
sorry bout that, it does work, i just forgot that after the hardy install i have a new username
all is good
thanks!
not working. yes you can open up gmail but not an email, nor a subject or body. Gmail hangs. Also sometimes the mailto.sh %s doesn’t seem to run.
ubuntu 7.10 gutsy
firefox 2.0.0.14
tried the perls script and others, can only open gmail.
nice idea, clearly it works for some of you. Just not for me for now.
scratch that.
ran DaveC’s perl line directly in the Custom line and it works, adds email, also adds subject line and body.
nice job
Thanks a lot!
This worked great when i was on FF# beta 5. Once FF3 final came out i had to change network.protocol-handler.external.mailto to true in about:config for it to work.
This works for both mailto links and sending regular URL’s with gmail. Copy and paste this directly into the Mail “custom” field of “Preferred Applications”.
perl -MURI::Escape -e ‘$to= shift; if ($to =~ /^([^\?]+)\?(.*)$/){$to=$1;$args=”&”.$2;$args=~s/\&subject=/&su=/};$to =~ s/^mailto://i; exec(”firefox”,”https://mail.google.com/mail/?view=cm&fs=1&tf=1&cmid=22&to=”.URI::Escape::uri_escape($to).$args);’ ‘%s’
Credits – dcc.vu/ubuntu-linux-file-send-link-with-gmail.html
Thanks a lot!!
The javascript given in Gmail’s blog didn’t work for me. ( I use Iceweasel in Debian )
But both The Geek’s script and DaveC’s script works fine!
Great job
For Opera 9.5x the following works:
opera –remote “openURL(https://mail.google.com/mail?view=cm&tf=0&to=`echo $1 | sed ’s/mailto://’`,new-tab)”
This line is basically the same as the firefox line except that :
1. There are two hyphens before ‘remote’
2. openurl needs to be replaced with openURL
Good job, Dave C.! I still don’t really understand all these linux commands and stuff, so thankfully somebody had the simple instructions.
Andrew’s Comment on June 28 works great for me–the others wouldn’t work or would not work with “subject” line
.
Firefox 3.0.1
Ubuntu 8.04.1
it’s simpler and just as (more?) effective to let gmail handle the mailto: URL.
Just put the following in the preference box:
“firefox https://mail.google.com/mail/?extsrc=mailto&url=%s“
Works fine when I want to email links from Firefox but I’m not given the option to use anything other than Evolution and Thunderbird if I want to send a saved file from my machine. Any tips?
This worked perfectly, thank you VERY much!
Hi. Great tutorial. I noticed that the chmod path needs to be pointed to the correct location of the script. In your case, ~/geek/open_mail.sh
Arguably, you should be placing your personal executables in /home/geek/bin. Then hide the bin folder if you want. bin is automatically added to your PATH variable if it exists (this occurs in your ~/.profile script). That way you can run the commands from a terminal without specifying the full path to the executable.
I’m using Firefox3 on Ubuntu Hardy and keep getting stuck in a redirect loop when using the provided script. Here’s my workaround: you need a &fs=1 in the URL like so:
#!/bin/sh
firefox -remote “openurl(https://mail.google.com/mail?view=cm&fs=1&tf=0&to=`echo $1 | sed ’s/mailto://’`,new-tab)”
It opens a new tab and opens a blank compose email page, but it doesn’t put address in the to field. Any ideas?
I took Nat’s line above because I have Firefox3.0.1 on Hardy also.
Ok, two things, using Ubuntu 8.04 and Firefox 3 the above explanation opens gmail, in a new tab ( ?? i DID NOT modify your file though??) into the compose mail. So all in all, it works fine…
But it doesn’t fill-in the to address. I have to go back to the orig. tab(where I clicked on the contact, or whatever it was) and copy and past the email address if I can see it or look at the preview bar at the bottom of firefox to see if that shows the actual address.
Is there any way to get it to populate the to: address?
Hi!
I don’t know why but it doesn’t work with Gnome-Do, which was the main reason I made this tweak.
I get an error “Redirect Loop: Firefox has detected that the server is redirecting the request for this address in a way that will never complete.”
I modified your script together with another to make this work in Mozilla Prism.
See my post here http://ubuntuforums.org/showth.....amp;page=2 for the script.
… it also handles the subject and body and someone ever wants to scrump that.
Thanks DaveC, that worked perfect!
I just can’t get this to work.
Ubuntu 8.04 64 bit
Firefox 3
Even uninstalled and reinstallled Firefox.
Any help for me?
TIA
zeddock
In firefox 3.0.3 (and earlier?) under Ubuntu 8.04 you can select Gmail directly as the preferred email application and then all this is done in the background.
You don’t actually have to create a full script. Just pass the firefox line to bash using the -c option.
In other words, instead of pasting “/home/geek/open_mailto.sh %s” into the Preferred Applications panel, paste the following:
bash -c ‘firefox -remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=`echo %s | sed ’s/mailto://’`,new-tab)”‘
No script needed. Works for me, anyway.
@Scott: “No script needed. Works for me, anyway. ”
I was trying to do the same thing, but well you came up with the code faster.
Thanks
This worked for me on Craigslist with Firefox 3.0.3 with Ubuntu 8.04 (hardy) as of Nov 11th 2008.
(as referenced from Billy Charlton)
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&ui=1&to=”`echo $1|sed -e ’s/?subject=/\&su=/’ -e ’s/mailto://’`
I don’t get it……
Why not just put the following in the custom command:
firefox https://mail.google.com/mail?view=cm&tf=0&to=%s
Or:
firefox –remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=%s,new-tab)”
No need to use a script file or sed.
Hey, thanks, this is great.
It doesnt quite work if the mailto link also has ?subject=make+me+better&body=heres+how
you just get an ugly looking email address, so I wrote this to make it work
hope you like it, and give it to every one
sorry my scripting is a little amatuerish. if any one has a better way to do it, let me know
—————————–
#!/bin/sh
TO=`echo $1 | sed ’s/mailto:\([^?]*\).*/\1/’`
SU=`echo $1 | sed ’s/.*subject=\([^&]*\).*/\&su=\1/’`
SU=`echo $SU | sed ’s/mailto:.*//’` #this is to get rid of the subject if nothing matched
CC=`echo $1 | sed ’s/.*cc=\([^&]*\).*/\&cc=\1/’`
CC=`echo $CC | sed ’s/mailto:.*//’`
BCC=`echo $1 | sed ’s/.*bcc=\([^&]*\).*/\&bcc=\1/’`
BCC=`echo $BCC | sed ’s/mailto:.*//’`
BODY=`echo $1 | sed ’s/.*body=\([^&]*\).*/\&body=\1/’`
BODY=`echo $BODY | sed ’s/mailto:.*//’`
firefox “https://mail.google.com/mail?view=cm&tf=0&to=$TO$SU$CC$BCC$BODY”
#firefox -remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=$TO$SU$CC$BCC$BODY,new-tab)”
——————————
it works with all the possible mailto; extras.
thanks again.
oh, I just saw
Soonlar’s
#!/bin/sh
firefox “https://mail.google.com/mail?view=cm&tf=0&ui=1&to=”`echo $1|sed -e ’s/?subject=/\&su=/’ -e ’s/mailto://’`
thats much better than what I wrote
This is the only one that works for me on FF3 and Ubuntu 8.10.
firefox –remote “openurl(https://mail.google.com/mail?view=cm&tf=0&to=%s,new-tab)”
Note that to use a script, which this entry is not, I had to put “sh ” in front of the entry for the prefered mail custom entry.
zeddock
Cheers.
Great Geeking!
I now use Mozilla Prism — after installing Gmail as an app, I set my preferred email as “prism-google-mail”. Pretty slick.
great! great! great!
Now I can enjoy gmail more fruitfully and in linux.
thanks for this tutorial
this is the best solution I’ve found:
http://dcc.vu/ubuntu-linux-fil.....gmail.html
try this instead:
http://xantus.vox.com/library/.....buntu.html
This is completely redundant if you use Mozilla Firefox.
Just go to Edit > Preferences > Applications and scroll down until you see the ‘mailto’ option.
Select ‘GMail’.
Presto, done.
Oh I forgot the icing on the cake….
In System > Preferences >Preferred Applications set your Mail Reader to ‘Custom’….
with the command ‘firefox %s’
Presto, done. Now anywhere in Ubuntu/Gnome you click a email link it will open in GMail.
Very nice; great.
I have never been able to get this or others to work. Evolution always tries to launch when I am outside of firefox.
Thanks, worked great for me!
Just a little hint,
if you want to have your full gmail page you need to change the code
firefox -remote “openurl(https://mail.google.com/mail/?view=cm&fs=1&to=`echo $1 | sed ’s/mailto://’`,new-tab)”
have fun
mns
Anyone know if there’s a url param that will let you add an attachment?
I’d like to make the “Send To” right-click work. It makes zip/tar.bz in a tmp dir so something like
“view=cm&fs=1&to=…&attach=/tmp/blah.zip” (except that’s not it…)
Seems a lot easier just to set up evolution to get you mail from gmail, maybe thats just me
@Don, thanks! Works very well if you just use the built-in Firefox feature!
A note to others reading this and trying it: The firefox solution doesn’t seem to work if you’re using Gmail in offline mode / unstable connection mode. Loads about 95% and then just stops.
Well this didn’t work for me. I even followed Don’s suggestion, but still nothing.
I’d love to get this to work though.
hello all,
for ubuntu user with the prism-google-mail apps,
#!/bin/sh
`echo “prism -uri https://mail.google.com/mail?view=cm&tf=0&to=“$1 | sed ’s/mailto://’`
enjoy
I suppose I should mention that everything listed says what it should say. In Firefox my preferred app is Gmail, in System > Preferences > Preferred applications everything is set properly AND it does remember it.
Yet, whenever I click on a mail link anywhere… and I mean anywhere… absolutely nothing happens. My screen blinks as if to tell me, “Yeah, I got that this is what you want to do, okay? But haven’t you figured out it isn’t going to freaking work???”
It’s really an annoyance. In fact, there are quite a few Ubuntu annoyances that bother me so much that I’m tempted to buy a version of Windows online. This was a completely clean install with hardly anything on it. However extremely simple, yet seriously important, things just do not work like headphones, flash, help files and probably more that I just don’t know about.
It’s not that I didn’t seek help, because I did. I sought help here, but there wasn’t any. I’ve sought help from the Ubuntu forums, but still no fixes. http://ubuntuforums.org/member.php?u=761967 > Statistics > Find all threads started
Sure, Ubuntu might have it’s pros, but the cons are beginning to outweigh the pros. When you can’t even problem solve by looking in the help files because even the help files do not work, then you have an issue.
Nowadays, in firefox (3.0) you can set handler to gmail in preferences, in firefox. that means, just set your system handler to “firefox %s” rather then a script. it’s a more complete solution.
konsumer’s solution works for me
If someone knows the answer for Scott’s question please share with us…