6

Using C#, how can I determine which program is registered as the default email client? I don't need to launch the app, I just want to know what it is.

Gabriel Mongeon
  • 7,251
  • 3
  • 32
  • 35
epotter
  • 7,631
  • 7
  • 63
  • 88

5 Answers5

11

Use the Registry class to search the registry. This console app demonstrates the principle.

using System;
using Microsoft.Win32;

namespace RegistryTestApp
{
   class Program
   {
      static void Main(string[] args)
      {
         object mailClient = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "", "none"); 
         Console.WriteLine(mailClient.ToString());
      }
   }
}
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
8

You can look in the registry on the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail
Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79
3

You can read this registry key from

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail
Irshad
  • 3,071
  • 5
  • 30
  • 51
Jonathan
  • 11,809
  • 5
  • 57
  • 91
3

Default email client depends on the user. HKLM lists all registered email clients; the first one returned may not be the current user's default. Better to read HKEY_CURRENT_USER\Software\Clients\Mail.

Also this only gives you the name of the email application. If you want its executable file name, you have to go on with something like:

object mailCommand = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\" + mailClient.ToString() + @"\shell\open\command", "", "none");

and then remove anything extraneous from the command-line string that you don't need (quotes, parameters).

1

I think you should be able to find that info in the registry at HKLM\Software\Clients\Mail.

Look for the default string value.

bruno conde
  • 47,767
  • 15
  • 98
  • 117