tags:

views:

1922

answers:

4

How do I make it so mailto: links will be registered with my program?

And then how would I handle that event in my program?

Most of the solutions I found from a quick Google search are how to do this manually, but I need to do this automatically for users of my program if they click a button such as "set as default email client".

Edit: Removed reference to Delphi, because the answer is independent of your language.

+3  A: 

From what I've seen, there are a few registry keys that set the default mail client. One of them being:

System Key: [HKEY_CLASSES_ROOT\mailto\shell\open\command] Value Name: (Default) Data Type: REG_SZ (String Value) Value Data: Mail program command-line

I'm not familar with Delphi 7, but I'm sure there are some registry editing libraries in there that you could use to modify this value.

Some places list more than this key, others just this key, so you may need to test a little bit to find the proper one(s).

Dillie-O
A: 

Here is the official Microsoft Solution to programatically change the default mail client. It's VBScript, but i hope the concept is clear from this:

http://support.microsoft.com/kb/299853

Michael Stum
From your link: "This is separate from the default Web browser or e-mail client that is used to start arbitrary URLs from anywhere in the system."That's also another thing I was wondering, but not really the answer to this question.
Liron Yahdav
+5  A: 

@Dillie-O: Your answer put me in the right direction (I should have expected it to just be a registry change) and I got this working. But I'm going to mark this as the answer because I'm going to put some additional information that I found while working on this.

The solution to this question really doesn't matter what programming language you're using, as long as there's some way to modify Windows registry settings.

Finally, here's the answer:

  • To associate a program with the mailto protocol for all users on a computer, change the HKEY_CLASSES_ROOT\mailto\shell\open\command Default value to:
    "Your program's executable" "%1"
  • To associate a program with the mailto protocol for the current user, change the HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command Default value to:
    "Your program's executable" "%1"

The %1 will be replaced with the entire mailto URL. For example, given the link:

<a href="mailto:[email protected]">Email me</a>

The following will be executed:
"Your program's executable" "mailto:[email protected]"

Note: The mailto syntax allows for more than just the email address.

Liron Yahdav
Have you checked whether now you can mark this as *the* answer? I don't know the minimum reputation required.
ΤΖΩΤΖΙΟΥ
Yes, I was now able to mark this as the answer.
Liron Yahdav
A: 

NOTE: This is a copy with formatting fixes of Liron Yahdav's answer that can be chosen as the correct answer. If you want to upvote it, upvote Liron's answer instead.

The solution to this question really doesn't matter what programming language you're using, as long as there's some way to modify Windows registry settings.

Finally, here's the answer:

  • To associate a program with the mailto protocol for all users on a computer, change the HKEY_CLASSES_ROOT\mailto\shell\open\command Default value to:
    "Your program's executable" "%1"
  • To associate a program with the mailto protocol for the current user, change the HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command Default value to:
    "Your program's executable" "%1"

The %1 will be replaced with the entire mailto URL. For example, given the link:

<a href="mailto:[email protected]">Email me</a>

The following will be executed:
"Your program's executable" "mailto:[email protected]"

Note: The mailto syntax allows for more than just the email address.

Other notes by Liron

@Dillie-O: Your answer put me in the right direction (I should have expected it to just be a registry change) and I got this working. But I'm going to mark this as the answer because I'm going to put some additional information that I found while working on this.

ΤΖΩΤΖΙΟΥ
Note: this will only affect IE, other browsers set their protocol handlers elsewhere.
Piskvor