Mailto Links and Zimbra [How to]

I’ve been looking throughout the Internet today looking for ways to get mailto: links to work with Firefox and Zimbra. Since I didn’t want to touch the registry and most of the people here use Macs anyway, I had to make a Greasemonkey script to do the job. Sure, there are already scripts to do this, but they point to the standard interface. I wanted the advanced interface.

First, take this code, put it in a text editor, and change “” to your zimbra server (2 instances).

// ==UserScript==
// @name Mailto Compose In Zimbra
// @namespace
// @description Rewrites "mailto:" links to Zimbra compose links
// @include *
// @exclude
// ==/UserScript==
(function() {
var processMailtoLinks = function() {
var xpath = "//a[starts-with(@href,'mailto:')]";
var res = document.evaluate(xpath, document, null,
var linkIndex, mailtoLink;
for (linkIndex = 0; linkIndex < res.snapshotLength; linkIndex++) {
mailtoLink = res.snapshotItem(linkIndex);
var m = mailtoLink.href;
var matches = m.match(/^mailto:([^\?]+)(\?([^?]*))?/);
var emailTo, params, emailCC, emailSubject, emailBody;
emailTo = matches[1];
//alert("Found to=" + emailTo);
params = matches[3];
if (params) {
var splitQS = params.split('&');
var paramIndex, param;
for (paramIndex = 0; paramIndex < splitQS.length; paramIndex++) {
param = splitQS[paramIndex];
nameValue = param.match(/([^=]+)=(.*)/);
if (nameValue && nameValue.length == 3) {
// depending on name, store value in a pre-defined location
switch(nameValue[1]) {
case "to":
emailTo = emailTo + "%2C%20" + nameValue[2];
case "cc":
emailCC = nameValue[2];
//alert("Found CC=" + emailCC);
case "subject":
emailSubject = nameValue[2];
//alert("Found subject=" + emailSubject);
case "body":
emailBody = nameValue[2];
//alert("Found body=" + emailBody);
mailtoLink.href = "" +
(emailTo ? ("&to=" + emailTo) : "") +
(emailCC ? ("&cc=" + emailCC) : "") +
(emailSubject ? ("&subject=" + emailSubject) : "") +
(emailBody ? ("&body=" + emailBody) : "");
// mailtoLink.onclick = function() { location.href = newUrl; return false; };
window.addEventListener("load", processMailtoLinks, false);

Then paste the code into the generator here:

Leave the GUID as it is, change the max version to 3.5.* and then add anything else you might want.

Compile the script and then install the .xpi file into firefox.

11 thoughts on “Mailto Links and Zimbra [How to]”

  1. i can get ZCS desktop to fire up on hitting mailto: but it doesn’t open a new mail with the address !

    your script is better !!

  2. massive !!

    works brilliantly and made me install greasemonkey which is really useful too – thanks 🙂

    out of interest how might you change the code to point to the ZCS desktop app as distinct from webmail ?


    1. @babysnake, I think in that case you can set Zimbra Desktop to be the default mail client and then remove the extension in firefox.

  3. Excellent!

    Give ’em an inch and theyt’ll take a mile: Can you expand this so it opens in a new broswer window somehow?

    top work – cheers!

    1. Its so when you click an email link in Firefox, it opens up Zimbra email.. much similar to Firefox having GMail and yahoo mail built in

  4. Well.. I run into a lot of problems at work with software and such and I always want to record them and post the solutions online. I’ve already passed this link on to a bunch of people and its already being used.

Comments are closed.