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

試著忘記壹切 提交于 2020-07-18 04:10:22

问题


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 Outlook, but what if one wants mailto: to open in, say, gmail.com?

What do I need to put in the mailto: statement for that to happen?


回答1:


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.




回答2:


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




回答3:


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!




回答4:


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.




回答5:


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).



来源:https://stackoverflow.com/questions/27176849/what-does-mailto-do-when-there-is-no-email-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!