Mailto Link

Forums General discussion Mailto Link

This topic contains 2 replies, has 2 voices, and was last updated by  Wilson 2 months ago.

  • Author
    Posts
  • #25295

    Wilson
    Participant

    Hi Alex,
    How can I construct the “Mailto” syntax within a function so that i can call the function from a button?

    Ultimately I just want to open the default mail client, auto populate the “To” and maybe subject line. Then the user can add to the body and send the mail manually?

    Thanks in advance,
    Bob

  • #25303

    Alexander Bautz
    Keymaster

    Add a button in HTML to call this function:

    function createMailToLink(){
        var a = document.createElement("a");
        a.setAttribute("href","mailto:email@domain.com?subject=Subject of email&body=First%20line%20ofbody%0Asecond%20line%20ofbody");
        document.getElementsByTagName("body")[0].appendChild(a);
        a.click();
    }

    Alexander

  • #25307

    Wilson
    Participant

    Thanks Alex,
    Made a quick tweak so I could control variables at runtime and Works like a charm! This will give me an email envelope icon next to the contacts’ name that opens mail client set to their email…

    
    
    function fnCustomerContactToolStrip()
    {var html2 = "<IMG src='https://abc123.sharepoint.com/Media/16x16/email_16.png' style='cursor: pointer; float: left; padding: 0px 0px 0px 5px'; title='e-Mail Contact...'; onclick='createMailToLink()'/>";
        jQuery("#sbs_Field_CustomerContact").after("<td>"+html2+"</td>");
    }
    
    function createMailToLink(){
        var vemail = 'email@domain.com';
        var vsubject = 'Test';
        var vemailBody = 'This is a test of the Emergency Broadcast System';
        var a = document.createElement("a");
        a.setAttribute("href","mailto:"+vemail+"?subject="+vsubject+"&body="+vemailBody);
        document.getElementsByTagName("body")[0].appendChild(a);
        a.click();
    }

You must be logged in to reply to this topic.