2

How to find default mail client using C#? i checked some posted here but it didn't help me..

I used this code

object mailClient = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "", "none");

In my computer both windows live mail and outlook installed and the defualt client is windows live mail however if i print mailclient it will show defualt mail client as outlook.

but if i use System.Diagnostics.Process.Start("mailto:") then it will open in windows live mail which is correct.

i need a method to find defualt client through C# code.....

4

2 回答 2

3

注册表项是:

机器:
HKEY_CLASSES_ROOT\mailto\shell\open\command

用户:
HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command

这些键的值是被执行的命令行,它们%1mailto:. 因此,您可能需要进行一些额外的解析才能获得可执行文件的路径:

示例:
"C:\PROGRA~2\MICROS~4\Office14\OUTLOOK.EXE" -c IPM.Note /m "%1"将需要成为"C:\PROGRA~2\MICROS~4\Office14\OUTLOOK.EXE".

于 2013-03-13T18:33:13.673 回答
0

要打开已填写“收件人”的邮件,请尝试

string target = "joe.doe@doecontry.dc";

string mailtoCommand =
    (string) Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command", @"", @"none");
mailtoCommand = mailtoCommand.Replace("\"", string.Empty).Replace("%1", target);

string arguments =
    mailtoCommand.Substring(mailtoCommand.ToLower().IndexOf(@".exe", StringComparison.Ordinal) + 4);

string fileName = mailtoCommand.Substring(0, mailtoCommand.Length - arguments.Length);

Process.Start(fileName, arguments);
于 2016-05-10T15:18:12.637 回答