# how to make mailto: links work with firefox and thunderbird

## dju`

another thread about this, but i get it working. this is taken from the mozillazine forums.

i'm using:

```
mozilla-firefox-0.8

mozilla-thunderbird-0.5-r1
```

1. install the mozex extension for firefox

get it from http://mozex.mozdev.org. currently i have mozex 1.07 installed.

in the mozex options, enable the intercept mailto: clicks. then set the mailer: command to the full path of a script, let's say, "/home/me/usr/bin/mailtoFirefoxThunderbird.sh %a %s".

2. create the /home/me/usr/bin/mailtoFirefoxThunderbird.sh script

open your favorite editor and copy/paste:

```
#!/bin/sh

export MOZILLA_FIVE_HOME="/usr/lib/MozillaThunderbird"

THUNDERBIRD_PATH=${MOZILLA_FIVE_HOME}

                                                                                                               

if [ -z "`/bin/ps x | /bin/grep \"[0-9] ${THUNDERBIRD_PATH}/thunderbird-bin\"`" ]; then

        # No MozillaThunderbird running

        ${THUNDERBIRD_PATH}/thunderbird -P default -compose "mailto:$1?subject=$2"

else

        # MozillaThunderbird running

        ${THUNDERBIRD_PATH}/thunderbird -remote "mailto($1?subject=$2)"

fi

```

save it to /home/me/usr/bin/mailtoFirefoxThunderbird.sh, and make it executable:

```
chmod +x /home/me/usr/bin/mailtoFirefoxThunderbird.sh
```

3. restart firefox

4. test

me@nowhere.com. i suggest you to test a link with a ?subject part. sorry, i wasn't able to reproduce a test link here with bbcode.

it should work now. the only thing we need is to get rid of the annoying mailto: is not a registered protocol message, which happens from times to times; however the compose window opens all the same. any suggestions and corrections are welcome, hope this helps.

----------

## rentonj7

thanks for this one dJu`

----------

## Bastux

Thanks Dju`

You can do the same with sylpheed  :Smile: 

install the mozex extension, enable the intercept mailto: click, and instead of MozillaThunderbird script, type :

```

sylpheed-claws --compose %a

```

at the mailer: command line.

----------

## mr.twemlow

For those of you who don't like adding extensions to firefox, here's how I did it:

Edit (or create) /home/username/.phoenix/DEFAULT/STRINGOFCHARACTERS/user.js

My file is /home/jef/.phoenix/default/nu0owawp.slt/user.js

Add the line 

```
user_pref("network.protocol-handler.app.mailto", "/home/jef/scripts/mailto");
```

Where /home/jef/scripts/mailto is the path to the script above.  But I had to edit the script to prevent it from putting mailto:name@name.com in the address instead of just name@name.com

How I did it is below, letting the html do the work of specifying address/subject/cc or whatever.  Works fine for me:

```

#!/bin/sh

export MOZILLA_FIVE_HOME="/usr/lib/MozillaThunderbird"

THUNDERBIRD_PATH=${MOZILLA_FIVE_HOME}

                                                                                                               

if [ -z "`/bin/ps x | /bin/grep \"[0-9] ${THUNDERBIRD_PATH}/thunderbird-bin\"`" ]; then

        # No MozillaThunderbird running

        ${THUNDERBIRD_PATH}/thunderbird -P default -compose "$1"

else

        # MozillaThunderbird running

        ${THUNDERBIRD_PATH}/thunderbird -remote "$1"

fi 

```

----------

## NewBlackDak

Just an FYI.  If you want Thunderbird to open weblinks you need a second script with 

```
#!/bin/sh

export MOZILLA_FIVE_HOME="/usr/lib/MozillaFirefox"

FIREFOX_PATH=${MOZILLA_FIVE_HOME}

                                                                                                               

if [ -z "`/bin/ps x | /bin/grep \"[0-9] ${FIREFOX_PATH}/firefox-bin\"`" ]; then

        # No MozillaFirefox running

        ${FIREFOX_PATH}/firefox -P default "$1"

else

        # MozillaFirefox running

        ${FIREFOX_PATH}/firefox -remote "openurl($1, new-tab)"

fi

```

and to add the lines

```
user_pref("network.protocol-handler.app.http", "~/scripts/http");

user_pref("network.protocol-handler.app.https", "~/scripts/http");
```

to your Thunderbird prefs file

----------

## mr.twemlow

Thanks for the tip.  I was just wondering how to do that.

mr.twemlow

----------

## dhurt

Thanks for the tips.  This is exactly what I was looking for.

 :Cool: 

----------

## allucid

To open a link from an email in thunderbird with firefox:

~/.thunderbird/default/<random crap>/user.js  (create this file if it doesn't exist)

```
user_pref("network.protocol-handler.app.http", "/usr/bin/firefox");

```

[edit] made a little more clearerLast edited by allucid on Mon May 10, 2004 10:41 pm; edited 3 times in total

----------

## TriKster_Abacus

Hello,

I did the setup as described in the posts found here. I can open a URL in Thunderbird.. it opens firefox, but the address bar shows the url being a link in the /tmp directory, not the url address of the website I clicked on.

So in the /tmp generated webpage made by clicking the link you cannot go past the first link you clicked on in the email message.

Is there a way around this? To get firefox to open a new webpage with the full url, so I can use all the links and the webpage as it really stands?

Thank you

Sincerely,

TriKster Abacus

----------

## allucid

 *TriKster_Abacus wrote:*   

> Hello,
> 
> I did the setup as described in the posts found here. I can open a URL in Thunderbird.. it opens firefox, but the address bar shows the url being a link in the /tmp directory, not the url address of the website I clicked on.
> 
> So in the /tmp generated webpage made by clicking the link you cannot go past the first link you clicked on in the email message.
> ...

 

look at my post directly above yours.  :Razz:  if you don't have a user.js just create one and put that line in it.

----------

## dju`

yeah, actually it's another problem from what this thread was initially about, but it's good to mention.

----------

## firephoto

Since I've been schooling myself on "101 ways to launch mozilla flavored apps" I figured I'd get my mailto: working without an extension.

This script will work with a default emerge of mozilla-thunderbird-bin. Just put it somewhere and make it executable and set your "network.protocol-handler.app.mailto" in about:config. It works if thunderbird is open, closed, doing something, whatever.

```

#!/bin/sh

#set -x # Uncomment "set -x" for debugging

export MOZILLA_FIVE_HOME="/opt/MozillaThunderbird"

#check if command line arguments have the form "mailto:somebody at somewhere.com?subject=something"

#if that's true put "somebody at somewhere.com?subject=something" in MAILTO address

MAILTO=`echo $@ | awk 'BEGIN{FS=":"} $1 ~ /mailto/ {print $2}'`

THUNDERBIRD_PATH="/opt/MozillaThunderbird"

if [ -z "`ps x | grep \"[0-9] ${THUNDERBIRD_PATH}/thunderbird\"`" ]; then

    # No thunderbird running

    /opt/MozillaThunderbird/thunderbird $@

else

    # thunderbird running - raise window

     /opt/MozillaThunderbird/thunderbird -remote "xfeDoCommand(openInbox)"

fi 

if [ -n "$MAILTO" ]; then

    /opt/MozillaThunderbird/thunderbird -remote "mailto($MAILTO)"

fi

```

*edited it so it should be a drop in replacement for the /usr/bin/thunderbird script. Called on it's own, thunderbird launches, called again the window is brought to the top, called from the browser with mailto: the compose window opens. This is for the thunderbird-bin package but I imagine it should work with the compiled version with changes to the paths.

Thanks to google and

http://www.wlug.org.nz/MozillaThunderbirdNotes

----------

## dhurt

Works well, thanks. That is a better solution than the ones put out my the mozdev.  Just a couple suggestions.  You define a varible for the path to Thunderbird and then do not use it.  A little pointless to setup the variable and then not use it   :Wink: .  Also, I was under the impression that /usr/lib/MozillaThunderbird was the default location for the install.  I did not change anything and that is where it is on my computer. 

```

THUNDERBIRD_PATH="/usr/lib/MozillaThunderbird"

if [ -z "`ps x | grep \"[0-9] ${THUNDERBIRD_PATH}/thunderbird\"`" ]; then

        # No thunderbird running

        ${THUNDERBIRD_PATH}/thunderbird $@

else

        # thunderbird running - raise window

        ${THUNDERBIRD_PATH}/thunderbird -remote "xfeDoCommand(openInbox)"

fi

if [ -n "$MAILTO" ]; then

        ${THUNDERBIRD_PATH}/thunderbird -remote "mailto($MAILTO)"

fi 

```

----------

## BlindSpy

awesome work guys =)

----------

## firephoto

Your version (for a source install correct?) cleans it up a lot and should make for an easier patch for an ebuild depending on if it's the bin or source version. I emailed they person who did the current thunderbird (bin?) script so maybe this can get some wider testing. 

```

#!/bin/sh

#set -x # Uncomment "set -x" for debugging

export MOZILLA_FIVE_HOME="/opt/MozillaThunderbird"

#check if command line arguments have the form "mailto:somebody at somewhere.com?subject=something"

#if that's true put "somebody at somewhere.com?subject=something" in MAILTO address

MAILTO=`echo $@ | awk 'BEGIN{FS=":"} $1 ~ /mailto/ {print $2}'`

#THUNDERBIRD_PATH="/usr/lib/MozillaThunderbird" #Uncomment for mozilla-thunderbird (source install)

THUNDERBIRD_PATH="/opt/MozillaThunderbird" #mozilla-thunderbird-bin

if [ -z "`ps x | grep \"[0-9] ${THUNDERBIRD_PATH}/thunderbird\"`" ]; then

    # No thunderbird running

    ${THUNDERBIRD_PATH}/thunderbird $@

else

    # thunderbird running - raise window

    ${THUNDERBIRD_PATH}/thunderbird  -remote "xfeDoCommand(openInbox)"

fi 

if [ -n "$MAILTO" ]; then

    ${THUNDERBIRD_PATH}/thunderbird -remote "mailto($MAILTO)"

fi

```

I've never used mozilla-launcher so I don't know how this affects that.

----------

## dhurt

Works fine here so far.  Have not had any problems with it.

 :Very Happy: 

----------

## pacman13

Would it not be possible to use Gnome's built in "Preferred Applications" to do this?  (or KDE's? .. but I'm using Gnome at the moment)

So far I have it -almost- working, just by putting this as my preferred mail reader:

```
thunderbird -remote "mailto (%s)"
```

the only problem is that the %s stays as a %s in the TO field, not as the e-mail address.  There may or may not be a way around this, but it seems MUCH more elegant than scripts, etc...

I'll play with it more later when I'm home from work, and post results if I get it working.

----------

## allucid

probably, but not everybody is using a DE. The script works well.

----------

## NewBlackDak

 *pacman13 wrote:*   

> Would it not be possible to use Gnome's built in "Preferred Applications" to do this?  (or KDE's? .. but I'm using Gnome at the moment)
> 
> So far I have it -almost- working, just by putting this as my preferred mail reader:
> 
> ```
> ...

 

Shouldn't you be using 

```
thunderbird -remote "mailto ($1)"
```

?

----------

## msimplay

newbie alert :p

what should i name the script and where should i put it ?

----------

## firephoto

I just put mine in /usr/bin/ and made it executable and I have mine named "thunderbird-mailto" and use it for any program, icon, etc that needs thunderbird. Just don't name it thunderbird or thunderbird-bin because an emerge will overwrite it.

----------

## msimplay

 *firephoto wrote:*   

> I just put mine in /usr/bin/ and made it executable and I have mine named "thunderbird-mailto" and use it for any program, icon, etc that needs thunderbird. Just don't name it thunderbird or thunderbird-bin because an emerge will overwrite it.

 

thanks for that but what executes the script ?

because firefox is relying on kde to handle mailto 

so do i set kde to launch the sh script when mailto link is clicked ?

----------

## firephoto

enter about:config in the address bar of firefox and look for:

network.protocol-handler.app.mailto

and set that to:

/usr/bin/thunderbird-mailto (or wherever/whatever you called it)

You can also make a file named user.js in your firefox profile directory.

~/.mozilla/firefox/default.***/user.js

```
user_pref("network.protocol-handler.app.mailto", "/usr/bin/thunderbird-mailto");
```

The second way is probably the "better" way but both should work. (I use the first)

*Oh and I'm not sure how you are getting KDE to handle the mailto with firefox?? If you have something set their that firefox is linked to you might disable it or clear it or??

----------

## kamagurka

amazing; finally firefox and thunderbird talk to each other (mind you, why they don't out of the box at least via the mozilla-laucher thing is beyond me).

----------

## stoffe

 *allucid wrote:*   

> To open a link from an email in thunderbird with firefox:
> 
> ~/.thunderbird/default/<random crap>/user.js  (create this file if it doesn't exist)
> 
> ```
> ...

 

Thanks, that simple little trick just worked(tm).  :Very Happy: 

Why this isn't available at least as an option is truly and utterly beyond me, since this is the least that people expect from any browser + mail app constellation, preview technology or not.  :Smile: 

----------

## msimplay

thanks everyone for this it worked like a charm  :Smile: 

----------

## Mad_Tiger

How can i get into mozex settings?

----------

## NewBlackDak

I've emerged Firefox 9.1, and this no longer works.

Firefox still calls Thunderbird fine.  Thunderbird will call firefox if's not already running, but it is running I get "Error: No running window found"

----------

## firephoto

Sounds like a mozilla-launcher problem.

If you grab one of the later branch builds for firefox they have a new startup script which obsoletes the Gentoo mozilla-launcher and lets you launch firefox directly without any extra voodoo scripts . I'm not sure if thunderbird has this script yet or not. There's been some changes in the xremote-client too I believe.

What does your user.js file look like for thunderbird?

I haven't been using the ebuilds for thunderbird or firefox lately because with the pre-compiled versions there seems to be some extra files added when they are emerged which seem to make them work different than when you install manually. I also didn't stay with the newer thunderbird because it segfaulted on me but I'm pretty sure that had to do with something else on my system.

The July 15th build is here which is what I've been using lately with no problems.

ftp://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2004-07-15-11-0.9/

Latest branch builds here.

ftp://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-0.9/

If you use any of these newer builds ,copy your /opt/firefox directory to a new name then unmerge. After that just unpack the new firefox in opt and replace the searchplugins and plugins directories with the ones from your older version. After that, make /usr/bin/firefox a symlink to /opt/firefox/firefox and then run firefox once as root, exit, and use as normal. Anything wanting to open urls with firefox just needs to be told that "firefox" is what to use. From the command line, something like "firefox http://www.google.com/linux" will launch urls.

----------

## r.j.hall

My default action after emerging firefox and thunderbird ~x86 versions and stable, was to call evolution when I clicked on a mail link.   Where is the setting that makes it behave that way.   I tried evolution but really didn't like it as much as mozilla 1.3 / thunderbird.   I can't see any reference to evolution anywhere in the settings.   You would have thought the default action would be to behave like mozilla 1.3 and call their own client rather than a third party one.

Also I don't have an entry in about:config for network.protocol-handler.app.mailto   I have network.protocol-handler.external.mailto  Is that the same thing but a different/new name?

Cheers

Rich

----------

## firephoto

You should create a user.js file in your profile directory for adding the proper config lines. You can do this for both thunderbird (to handle urls) and firefox (for the mailto).

I don't know where the default mail handler settings are in Gnome but I'm sure someone can point you to the "simple" hole their tucked away in.  :Wink: 

----------

## Zapp

How do I get to the mozex options?  I am using 0.9.1 Firefox, and I cannot locate the mozex options in the Preferences.  Mozex shows up just fine in the context menu.

Sorry if this is a stupid noob question, but I cannot seem to figure it out.

Thanks.

----------

## Zapp

btt

----------

## gilkyboy

is it possible to do this with the ending extension .ebuild so that when I click on a link to an e-build, it adds itself to the portage overlay???  Kinda like our own little CNR (Click n' Run) thing, that would be awesome... talk about converting new users.....  Maybe even have it so they can set it up to be binary only..., maybe.

----------

## mallchin

 *pacman13 wrote:*   

> Would it not be possible to use Gnome's built in "Preferred Applications" to do this?  (or KDE's? .. but I'm using Gnome at the moment)
> 
> So far I have it -almost- working, just by putting this as my preferred mail reader:
> 
> ```
> ...

 

Agreed; Assuming you have an extensive DM (Gnome/KDE) I think Firefox should use whatever default mailto handler you have set.

I also use Gnome and Evolution is configured as default. Epiphany detects this however Firefox states mailto is not a registered protocol. Hrm.

----------

## silentbob

Nice thread, it should help out nicely!

----------

## jaybird

I didn't like this mozex method as any module that doesn't have an uninstall just doesn't seem worth using and I've noticed the patch has to be updated as they changed the binary filename of thunderbird.

I moved from evolution to thunderbird and I just have KDE installed (no Gnome).  I figured I could go to the KDE component chooser and tell it to use thunderbird but firefox still kept going to the old evolution installation.  Then I remembered when evolution installed it installed the gnome controls so sure enough I checked the gconftool-2 --get command and saw that this gnome control tool was forcing things to go to evolution still.

So I simply ran the following command at a terminal prompt and the entire problem was fixed without any extra extensions or patches.

```
gconftool-2 --set /desktop/gnome/url-handlers/mailto/command -t string 'thunderbird %s'
```

Oh, you can also alter the default browser here too

```
gconftool-2 --set /desktop/gnome/url-handlers/http/command -t string 'firefox %s'

gconftool-2 --set /desktop/gnome/url-handlers/https/command -t string 'firefox %s'
```

Enjoy the simplicity :)Last edited by jaybird on Mon Sep 20, 2004 6:28 am; edited 1 time in total

----------

## NewBlackDak

UPDATE!!

If you're using firefox 9.1 or newer, your http script needs to be updated to the following.

```
#!/bin/sh

export MOZILLA_FIVE_HOME="/usr/lib/MozillaFirefox"

FIREFOX_PATH=${MOZILLA_FIVE_HOME}

                                                                                                               

if [ -z "`/bin/ps x | /bin/grep \"[0-9] ${FIREFOX_PATH}/firefox-bin\"`" ]; then

        # No MozillaFirefox running

        firefox -P default "$1"

else

        # MozillaFirefox running

        firefox -remote "openurl($1, new-tab)"

fi

```

----------

## Paranoid

Just wanted to add an update to this as I recently switched to thunderbird as my email client. Easier than ever, just add: 

```
user_pref("network.protocol-handler.app.mailto", "/usr/bin/thunderbird");
```

to your firefox prefs.js file. No need for an extra script anymore, mozilla-launcher script handles it just fine.

To get urls from thunderbird to open in firefox just add: 

```
user_pref("network.protocol-handler.app.http", "/usr/bin/firefox");

user_pref("network.protocol-handler.app.https", "/usr/bin/firefox");
```

to your thunderbird prefs.js file.

versions:

firefox -1.0_pre-r2

thunderbird-0.8

mozilla-launcher-1.21

----------

## dayul

Hi, has anyone managed to get a url from thunderbird to open in firefox in a new tab instead of opening a new window?

----------

## NewBlackDak

In your thunderbird prefs, make sure that 

```
user_pref("network.protocol-handler.app.http", "/usr/bin/firefox");

user_pref("network.protocol-handler.app.https", "/usr/bin/firefox");
```

is removed or commented out incase you want go go back later.

Make them

```

user_pref("network.protocol-handler.app.http", "~/scripts/http");

user_pref("network.protocol-handler.app.https", "~/scripts/http");

```

The "~/scripts/http" is wherever you have the following script saved.

Your script should look like 

```

#!/bin/sh

PS=`/bin/ps x`

RUN=`echo $PS | grep firefox-bin`

if test "$RUN" = ""; then

        # No MozillaFirefox running

        firefox -P default "$1"

else

        # MozillaFirefox running

        firefox -remote "openurl("$1", new-tab)"

fi

```

Been working fine for me, but forgot to come back here, and update.

Edited this, because I pasted in the old script the first time accidentally.

----------

## dayul

thats great, thanks a lot, i was putting 

firefox -remote "openurl("$1", new-tab)

directly in the prefs.js file, which didnt work, but your script even checks for if firefox is not open!

works a treat, what a star you are.

----------

## NewBlackDak

 *dayul wrote:*   

> thats great, thanks a lot, i was putting 
> 
> firefox -remote "openurl("$1", new-tab)
> 
> directly in the prefs.js file, which didnt work, but your script even checks for if firefox is not open!
> ...

 

Take a look at again.  I accidentally copied the old one in.  That one doesn't work if ff isn't already running, but what I just edited does.

----------

## firephoto

If things haven't changed much then /usr/bin/firefox is just a link to the mozilla-launcher script which you could open up and change the correct line to say new-tab instead of new-window.

This is the line from the /usr/libexec/mozilla-launcher that you would change.

```

# new windows instead of new tabs

newtype=${MOZILLA_NEWTYPE:-"window"}

```

Also you should be able to call the firefox script that installs with firefox directly. It would be /opt/firefox/firefox or /usr/lib/MozillaFirefox/firefox(I'm not sure?) so have your user.js for thunderbird point directly to the mozilla script that installs with firefox (not the gentoo mozilla-launcher script/link).

```

user_pref("network.protocol-handler.app.http", "/path/to/mozilla-firefox-script");

user_pref("network.protocol-handler.app.https", "/path/to/mozilla-firefox-script");

```

This script is the one located in the base directory of where firefox is installed to and it's called "firefox" unless Gentoo changes that name for the source install.

One of the fixes before firefox went stable was make the launching of firefox or thunderbird directly without extra command line options or wrapper scripts necessary and this would obey to the settings for each program so if new windows opened in tabs then when a url was called from somewhere else firefox would know to open that in a new tab. This was working 6 months ago so I'm sure it hasn't been broken again.

I don't use thunderbird anymore but the method of launching firefox directly for urls, or thunderbird for mailto's, by directly pointing to the mozilla built script always worked for me once this feature was fixed by mozilla.

----------

## NewBlackDak

 *firephoto wrote:*   

> If things haven't changed much then /usr/bin/firefox is just a link to the mozilla-launcher script which you could open up and change the correct line to say new-tab instead of new-window.
> 
> This is the line from the /usr/libexec/mozilla-launcher that you would change.
> 
> ```
> ...

 

never even looked at this before, but yes changing to 

```

# new windows instead of new tabs

#newtype=${MOZILLA_NEWTYPE:-"window"}

newtype=${MOZILLA_NEWTYPE:-"tab"}

```

Works just the same

----------

## dayul

lol, thatll teach me for not testing it fully,

new one works great, thanks again.

----------

## Lokheed

 *Paranoid wrote:*   

> Just wanted to add an update to this as I recently switched to thunderbird as my email client. Easier than ever, just add: 
> 
> ```
> user_pref("network.protocol-handler.app.mailto", "/usr/bin/thunderbird");
> ```
> ...

 

Awesome. Works like a charm. Thanks for this quick and easy "proper" way of doing it. Those two things have bugged me for a long time.

I can confirm it works on Firefox 1.0 and Thunderbird 1.0  :Very Happy: 

NOTE: You also dont need mozilla-launcher either.

----------

