Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prefill an email with HTML content

I've been working on a project with a feature so that when I click a button, Outlook will open and the corresponding value stored in a variable will be in the in the body of the mail. I've tried the following code:

<html>
<head>
    <title>Email This Code Snippet</title>
    <script language="javascript">
    function TriggerOutlook()
    {         
        var sub = "Hi friend";
        var bodycont = "<html><body>welcome</body></html>";
        var body = escape(bodycont + String.fromCharCode(13));        
        window.location.href = "mailto:[email protected]"
                             + "?body=" + body
                             + "&subject=" + sub
        ;                
    }    
</script>
</head>
<body>
<form id="form1">
    <a href="#" onclick="TriggerOutlook()">Email this Codesnippet</a>
    <input type="text" name="txtbody" id="txtbody">
</form>
</body>
</html>

But the body of the mail is <html><body>welcome</body></html> in plain text, not HTML. How do I get it formatted as HTML?

like image 663
Sakthivel Avatar asked Apr 06 '09 13:04

Sakthivel


2 Answers

Interestingly, your code works for me as-is when Thunderbird is the default system mailer. Apparently Thunderbird is smart enough to notice that the body starts with <html> and switches to HTML-mail mode.

It would seem at first that to convince Outlook to behave similarly, you might try setting the Content-Type header in the email to "text/html". However, I don't see how this is possible using mailto since you do not have control over the headers.

like image 22
David Citron Avatar answered Oct 19 '22 23:10

David Citron


You can't. The mailto specification doesn't have that kind of control over the e-mail client invoked by the browser.

like image 175
Welbog Avatar answered Oct 19 '22 22:10

Welbog