Friday, October 02, 2009

Tidbit: Using Yahoo as your default email client

I just wrote a post on using GMail as your default email client and I thought there should be an easy way to do this for Yahoo Mail as well. And of course there is! Create a bash script with the following code and use it just as you would the gmailer script from the other post.



#!/bin/bash

getopen () {

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

getemail () {

export address=`echo $1 | sed 's/mailto://'`
export targeturl="http://compose.mail.yahoo.com/?To=$address"
}

getopen
getemail $1
exec $opener $targeturl
exit 0

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.



#!/bin/bash

getopen () {

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

getemail () {

export address=`echo $1 | sed 's/mailto://'`
export targeturl="https://mail.google.com/mail/?view=cm&fs=1&tf=1&source=mailto&to=$address"
}

getopen
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 emailaddress@isp.com 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.