不存在 mailto 协议处理程序时的故障转移

Failover when mailto protocol handler is not present

我在使用标签中的 mailto link 时遇到了一个小问题。

事实上,我添加了一个包含 mailto link 的标签,并且程序以本机方式尝试使用用户定义的默认程序打开它。

但实际上它不起作用并在没有此协议的默认程序时引发 Win32Exception

所以我强制打开浏览器,但它也不起作用...

这是我的代码示例:

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    // Specify that the link was visited.
    this.linkLabelContactEmail.LinkVisited = true;
    try
    {
        // Open the default program to send an email.
        System.Diagnostics.Process.Start("mailto:contact@mysite.fr");
    }
    catch (Win32Exception)
    {
        // Force opening in a browser
        System.Diagnostics.Process.Start("http://mailto:contact@mysite.fr");
    }
}

但它不起作用:/(如果默认程序是 link 该协议,它就起作用)

有谁知道我该如何解决这个问题? 就像强制将默认协议添加到 mailto link ?


编辑:

我试过了,效果很好!但它仍然无法处理 linux 浏览器:/ 而且它不是 Unix OS 下的 .exe,我应该如何尝试? (我知道 firefox 是默认安装的,它会被处理吗?)

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    // Specify that the link was visited.
    this.linkLabelContactEmail.LinkVisited = true;

    try
    {
        // Open the default program to send an email.
        System.Diagnostics.Process.Start("mailto:contact@mysite.fr");
    }
    catch (Win32Exception)
    {
        try
        {
            // Force opening in Firefox
            System.Diagnostics.Process.Start("firefox", "mailto:contact@mysite.fr");
        }
        catch (Win32Exception)
        {
            try
            {
                // Force opening in IE
                System.Diagnostics.Process.Start("chrome", "mailto:contact@mysite.fr");
            }
            catch (Win32Exception)
            {
                try
                {
                    // Force opening in IE
                    System.Diagnostics.Process.Start("iexplore", "mailto:contact@mysite.fr");
                }
                catch (Win32Exception)
                {
                    MessageBox.Show(
                        "Vous n'avez aucun programme par défaut de configuré pour envoyer un mail, ni aucun des 3 navigateurs (Firefox, Chrome, Internet Explorer). Nous ne pouvons donc vous aidez à envoyer ce mail...",
                        "Erreur à l'envoi du mail",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1
                    );
                }
            }
        }
    }
}

无需添加 http:// 协议前缀,您只需启动浏览器即可。您的 URL 语法无效,我怀疑它是否会起作用(Chrome 不确定,只是测试过)。

System.Diagnostics.Process.Start("iexplore", "mailto:contact@mysite.fr");

此代码打开 Internet Explorer 以执行 mailto: