O'Reilly logo

Greasemonkey Hacks by Mark Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #63. Compose Your Mail in Gmail

Make mailto: links open the Gmail compose page.

The Web comprises many kinds of resources: web pages, newsgroups, IRC channels, FTP sites, and so on. Each kind of resource has a scheme, such as the http: in http://mozilla.org or the irc: in irc://irc.mozilla.org/firefox.

You've probably seen mailto: links on contact pages; when you click the link, it launches an external email program.

But what if you use a web mail service such as Gmail? Normally, getting mailto: links to launch a web-based email application is nontrivial. You would basically need to write an external mail program that switched back to your browser and opened the appropriate URL. What a pain! This hack solves the problem another way, by rewriting mailto: links to point to the Gmail Compose page.

The Code

This user script runs on all pages. From a high-level view, it sounds deceptively simple. Just find all the mailto: links, parse them, and replace them with links to Gmail. When you click the link, the browser just redirects to the Gmail Compose page instead of launching a separate application.

Of course, it's not really that simple. The problem is that mailto: links can be complex. RFC 2368, entitled "The mailto URL scheme," specifies the format. The overall structure is mailto:<recipient>?<querystring>, where <querystring> is a list of <name>=<value> pairs separated by ampersands (&). We want to pass these name/value pairs to Gmail, but, of course, Gmail's Compose page uses a different ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required