简体   繁体   English

用HTML内容预填充电子邮件

[英]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. 我一直在研究具有功能的项目,因此当我单击按钮时,Outlook将打开,并且存储在变量中的相应值将位于邮件的正文中。 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:sakthivela@yahoo.com"
                             + "?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. 但是邮件的正文是<html><body>welcome</body></html> ,而不是HTML。 How do I get it formatted as HTML? 如何获得格式化为HTML的格式?

You can't. 你不能 The mailto specification doesn't have that kind of control over the e-mail client invoked by the browser. mailto规范对浏览器调用的电​​子邮件客户端没有这种控制。

Interestingly, your code works for me as-is when Thunderbird is the default system mailer. 有趣的是,当Thunderbird是默认系统邮件程序时,您的代码按原样对我有用。 Apparently Thunderbird is smart enough to notice that the body starts with <html> and switches to HTML-mail mode. 显然,雷鸟很聪明,可以注意到正文以<html>开头并切换到HTML邮件模式。

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". 乍看起来,为了说服Outlook具有类似的行为,您可以尝试将电子邮件中的Content-Type标头设置为“ text / html”。 However, I don't see how this is possible using mailto since you do not have control over the headers. 但是,我看不到使用mailto怎么可能,因为您无法控制标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM