views:

1288

answers:

6

Is there a way to implement a mailto: link that works with webmail clients?

Edit - so a traditional mailto link is (as I suspected) not going to work. So has anyone seen anything similar to those rss buttons you see with a variety of the most popular sites on?

+13  A: 

The links are handled by the user's browser. GMail has a client-side install (GMail Notifier) that lets you specify that you want GMail to handle all mailto links.

But there's no way for a web page to specify that it's mailto link should be handled by a webmail app (even if it could, how would you know which one?).

brien
You answered the exact same thing as I was going to:)Prize to the fastest typer:)
Antonio Louro
This may change in HTML5, where things like registerProtocolHandler() allows site to define handlers for custom protocols. http://www.w3.org/TR/html5/browsers.html#custom-handlers
molf
Gmail Notifier doesn't seem to work for Gmail Business accounts. For that you'll need to either copy and paste the link into your webmail.
blesh
To be more specific, I meant it doesn't work with Google Apps email.
blesh
+2  A: 

I am just brainstorming here. You might be able attach a Javascript handler to the link that asks the user if s/he wants to login to a webmail account (along with a list of providers). If you have the correct URLs for the webmail providers, you would then be able to invoke them on the basis of the user's choice. If the user answers no, return true from the handler and presumably the link would work normally.

See, for example, http://toric.blogspot.com/2005/07/gmail-compose-link.html and http://blog.monstuff.com/archives/000238.html

Sinan Ünür
+5  A: 

That's really more of a web client issue, it's already available for Firefox:

http://starkravingfinkle.org/blog/2008/04/firefox-3-web-protocol-handlers/

but ultimately it's down to the user to decide how their browser handles mailto links.

Andru
A: 

Hypothetically, assuming the webmail client passes arguments through the authentication process (or the user is already authenticated), I don't see why this is so impossible. It can't be done in the simple mailto: way, but it'd be possible to provide a selection of links to popular webmail services and use Javascript to intercept clicks on mailto: links such that the user is presented with a drop-down list of possible webmail services (or their local email client). The links would carry the To:/Subject: address but formed in whatever structure that webmail service requires.

Alistair Knock
+1  A: 

Here are 2 Opera UserJS examples that you can inspect to give you and idea of how you can do it on a regular pages. (Obviously, UserJS-specific functions wouldn't work in a regular page, but you can use regular events.)

This one catches left-clicks on mailto links and opens them in Gmail for example. It can also handle forms.

http://shadow2531.com/opera/userjs/BeforeMailtoURL.js

This one catches all mailto actions, has a more generic parser (that supports any hname and not just to, cc, bcc, subject and body) and has a better format string syntax:

http://shadow2531.com/opera/userjs/BeforeMailtoURL.zip

Basically, you have to find a way to intercept mailto link actions. You can do this with click event listeners on links and submit listeners on forms (if you really want to support forms). (It's easier to use a click event listener on the whole window and just filter it to find mailto actions. That way, you catch mailto links that are dynamically added at some arbitrary time.)

Or, you can just run through the page and process all the mailto links.

But, if you want to intercept mailto actions in the address field, via window.open or document.location etc., you'll need something like HTML5's registerProtocolHandler or something like Opera's webmailprovider.ini support. You can use registerProtocolHandler in Firefox, but by default, it's restricted to the domain you set it on.

So, basically, you either convert mailto links to http(s) webmail compose URIs up front, or at the time the mailto action is invoked. The latter works much better.

Converting a mailto link to a webmail compose URI involves a few things. First, you need to know what query string variables the webmail accepts. Then, you need to parse the mailto URI to split it up into the parts you want. Then, you need to decode and re-encode (to normalize) those parts. Then, you need to join multiple occurrences of hvalues together. And, you need to handle things in a case-insensitive manner and check for and escape unsafe characters and %HH etc.

For the parsing, you can do a quick and dirty regex, but you'll get better results with a full mailto URI parser and normalizing functions.

So, if you just want to handle left-clicking on links, you can do that cross-browser. For more than that, you have to use any hooks the particular browser gives you.

Shadow2531
A: 

If you're using a Google Apps email account (hosted email), than Gmail Notifier will not work. You can use a bookmarklet though, to change all of your mailto: links to links that point to your webmail.

Here's a bookmarklet I wrote to do just that, it will highlight all fixed links in red.

javascript:for(var i=0;i<document.links.length;i++){var a=document.links[i];if(a.href.indexOf('mailto:')==0){a.href='http://mail.google.com/a/sample.com/mail?extsrc=mailto&amp;url='+a.href;a.style.backgroundColor='red';a.style.color='white'}};return true;

Just be sure to change http://mail.google.com/a/sample.com to whatever the proper hosted address is for you.

I suppose this will work with a number of other email clients if you just change that link around.

blesh