What does `mailto:` do when there is no email client?

后端 未结 5 2260
忘掉有多难
忘掉有多难 2021-02-20 10:08

I am developing a website.

What does mailto: open in if there is no email client (like Outlook, Thunderbird, etc.)? It works on my computer, which has Outlo

相关标签:
5条回答
  • 2021-02-20 10:37

    What happens is entirely up to the client. The OS defines protocol handlers for protocols like mailto: or tel:, etc.

    You would need access to the client's registry (in case of a Windows system) to manipulate the handling application for your protocol handler.

    For Outlook 2013 as the designated handler, the according Registry structure looks like this:

    [HKEY_CLASSES_ROOT\mailto]
    @="URL:mailto"
    "EditFlags"=hex:02,00,00,00
    "URL Protocol"=""
    
    [HKEY_CLASSES_ROOT\mailto\DefaultIcon]
    @="C:\\PROGRA~2\\MICROS~1\\Office15\\OUTLOOK.EXE,-9403"
    
    [HKEY_CLASSES_ROOT\mailto\shell]
    @="open"
    
    [HKEY_CLASSES_ROOT\mailto\shell\open]
    
    [HKEY_CLASSES_ROOT\mailto\shell\open\command]
    @="\"C:\\PROGRA~2\\MICROS~1\\Office15\\OUTLOOK.EXE\" -c IPM.Note /mailto \"%1\""
    

    with a corresponding structure under HKCU.

    0 讨论(0)
  • 2021-02-20 10:39

    The following solution works for me:

    (function($)) {
      $('a[href^=mailto]').each(function() {
        var href = $(this).attr('href');
        $(this).click(function() {
          var t;
          var self = $(this);
    
          $(window).blur(function() {
            // The browser apparently responded, so stop the timeout.
            clearTimeout(t);
          });
    
          t = setTimeout(function() {
            // The browser did not respond after 500ms, so open an alternative URL.
            document.location.href = '...';
          }, 500);
        });
      });
    })(jQuery);
    

    For more info see: https://www.uncinc.nl/articles/dealing-with-mailto-links-if-no-mail-client-is-available

    0 讨论(0)
  • 2021-02-20 10:42

    As a web developer you don't have any control over the software that a user chooses to open their email, since it's handled by that user's web browser settings, or the OS. If a user has no email program installed on their machine and no operation defined for "mailto" links in their browser, nothing would happen.

    0 讨论(0)
  • 2021-02-20 10:50

    I believe you can use this. https://mail.google.com/mail/?view=cm&fs=1&to=email@domain.com This however does have its flaws in which the user must be already signed into gmail. Hope this helps!

    0 讨论(0)
  • 2021-02-20 10:51

    The mailto URI scheme doesn't decide what happens-- it simply instructs the browser you're using to do whatever it's been configured to do to send e-mails (see the IETF proposed standard for more info). Therefore, you'll have to consult the browser itself to see what it does if no e-mail client is configured.

    According to the documentation and to my personal experience, I don't see any way of manually setting an action: It might be possible with certain browsers with some non-standard syntax, but this is unlikely since this would open up a huge potential security problem by being able to execute an arbitrary command by click (such as downloading a virus or something like that).

    0 讨论(0)
提交回复
热议问题