Automatically open default email client and pre-populate content

后端 未结 4 580
孤独总比滥情好
孤独总比滥情好 2020-11-29 03:12

I need to automatically open a user\'s default email client when they save some content on a page. I need to populate the email subject, to address, and put some content in

相关标签:
4条回答
  • 2020-11-29 03:40

    JQuery:

    $(function () {
          $('.SendEmail').click(function (event) {
            var email = 'sample@gmail.com';
            var subject = 'Test';
            var emailBody = 'Hi Sample,';
            var attach = 'path';
            document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody+
                "?attach="+attach;
          });
        });
    

    HTML:

     <button class="SendEmail">Send Email</button>
    
    0 讨论(0)
  • 2020-11-29 03:54

    Try this: It will open the default mail directly.

    <a href="mailto:demo@demo.com"><img src="ICON2.png"></a>
    
    0 讨论(0)
  • 2020-11-29 03:56

    As described by RFC 6068, mailto allows you to specify subject and body, as well as cc fields. For example:

    mailto:username@example.com?subject=Subject&body=message%20goes%20here
    

    User doesn't need to click a link if you force it to be opened with JavaScript

    window.location.href = "mailto:user@example.com?subject=Subject&body=message%20goes%20here";
    

    Be aware that there is no single, standard way in which browsers/email clients handle mailto links (e.g. subject and body fields may be discarded without a warning). Also there is a risk that popup and ad blockers, anti-virus software etc. may silently block forced opening of mailto links.

    0 讨论(0)
  • 2020-11-29 04:00

    Implemented this way without using Jquery:

    <button class="emailReplyButton" onClick="sendEmail(message)">Reply</button>
    
    sendEmail(message) {
        var email = message.emailId;
        var subject = message.subject;
        var emailBody = 'Hi '+message.from;
        document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody;
    }
    
    0 讨论(0)
提交回复
热议问题