【问题标题】:Failover when mailto protocol handler is not present不存在 mailto 协议处理程序时的故障转移
【发布时间】:2015-03-18 15:47:07
【问题描述】:

我在标签中的 mailto 链接方面遇到了一点问题。

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

但实际上它不起作用并在没有此协议的默认程序时引发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");
    }
}

但它不起作用:/(如果默认程序链接到该协议,它就会起作用)

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


编辑:

我试过了,效果很好!但它仍然无法处理 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
                    );
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# .net mailto linklabel


    【解决方案1】:

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

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

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

    【讨论】:

    • @Fik:需要更多帮助吗?如果没有,如果对您有帮助,请采纳答案。
    • 谢谢!如果我在 Linux 操作系统下运行,我该如何处理?或者如果用户卸载了 IE ?我怎么称呼 Firefox 或 Chrome ?还是 Linux 浏览器?
    • 它适用于 firefox,我认为它适用于 IE,就像你回答的那样,我希望它适用于 Chrome,因为它会在我尝试通过命令提示符启动 Chrome 时启动。
    • @Fikkwix:只需将另一个浏览器 exe 作为第一个参数。您可能需要做一些工作才能真正找到该 exe。
    猜你喜欢
    • 2012-06-04
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多