Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mailto: links and webmail

Tags:

html

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?

like image 272
SillyMonkey Avatar asked May 28 '09 12:05

SillyMonkey


People also ask

Do mailto links work in Outlook?

Insert a link that opens a new email and pre-fills the email address, subject line, and body content. A mailto link is clickable text that automatically opens a new email in the reader's default email client, such as Outlook or Gmail, and pre-fills the "To" email address.

Should you use mailto links?

A mailto link is different than a contact form link. Essentially, an HTML mailto link is a link that triggers the user's default mail client to open so they can reply to a message. If you're a fan of email HTML forms and know your way around the coding aspect of things, a mailto link can be preferable, in some cases.

What are mailto links?

Email (mailto) links are used for linking directly to an email address, which will automatically launch an email browser when the link is clicked.


5 Answers

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?).

like image 187
brien Avatar answered Oct 03 '22 14:10

brien


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.

like image 38
Andru Avatar answered Oct 03 '22 15:10

Andru


Create a text file named MailtoWebMail.reg with the following content...

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command]

@="\"(BrowserExecutable)\" (Parameters)"

where (BrowserExecutable) is replaced with the complete path to your browser (ie. C:\Program Files\Internet Explorer\iexplore.exe) and (Parameters) is replaced with the appropriate line for the mail service as described below...

GMail "http://mail.google.com/mail/?view=cm&fs=1&to=%1"

Hotmail "http://hotmail.msn.com/cgi-bin/compose?To=%1&mailto=1"

Yahoo Mail "http://compose.mail.yahoo.com/?To=%1"

Netscape Mail "http://webmail.netscape.com/compose.adp?mailto=%1"

Mail.com "http://mail01.mail.com/scripts/mail/Outblaze.mail?composeto=%1&compose=1"

Opera Web Mail "http://mymail.operamail.com/scripts/mail/Outblaze.mail?compose=1&did=1&a=1&to=%1"

Note: There should not be a blank line after the [HKEY_LOCAL_MACHINE] line

MikeB

like image 39
MikeB Avatar answered Oct 03 '22 16:10

MikeB


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

like image 29
Sinan Ünür Avatar answered Oct 03 '22 15:10

Sinan Ünür


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.

like image 39
Shadow2531 Avatar answered Oct 03 '22 16:10

Shadow2531