我可以在mailto 部分插入HTML格式的正文hre..."> 我可以在mailto 部分插入HTML格式的正文hre..."/> 我可以在mailto 部分插入HTML格式的正文hre..."> 我可以在mailto 部分插入HTML格式的正文hre...">

具有HTML正文的mailto链接

HTML

DavaidTony宝儿

2020-03-24

mailto在HTML文档中有几个链接。

<a href="mailto:etc...">

我可以在mailto:部分插入HTML格式的正文href吗?

<a href="mailto:me@me.com?subject=Me&body=<b>ME</b>">Mail me</a>

请注意,在iOS中(2016),添加<i><b>标记以简单的斜体,粗体格式非常好。

第3327篇《具有HTML正文的mailto链接》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

10个回答
番长猴子 2020.03.24

我以这种方式工作:

var newLine = escape("\n");
var body = "Hello" + newLine +"World";

输出为:

Hello
World  
梅Harry 2020.03.24

任何人都可以尝试以下操作(mailto函数仅接受纯文本,但在这里我展示了如何使用HTML内部文本属性以及如何将锚点添加为mailto正文参数):

//Create as many html elements you need.

const titleElement = document.createElement("DIV");
titleElement.innerHTML = this.shareInformation.title; // Just some string

//Here I create an <a> so I can use href property
const titleLinkElement = document.createElement("a");
titleLinkElement.href = this.shareInformation.link; // This is a url

...

let mail = document.createElement("a");

// Using es6 template literals add the html innerText property and anchor element created to mailto body parameter
mail.href = 
  `mailto:?subject=${titleElement.innerText}&body=${titleLinkElement}%0D%0A${abstractElement.innerText}`;
mail.click();

// Notice how I use ${titleLinkElement} that is an anchor element, so mailto uses its href and renders the url I needed
小宇宙 2020.03.24

可以输入unicode值以插入换行符(即:),\u0009但是HTML标签具有不同程度的支持,应避免使用。

乐米亚 2020.03.24

雷鸟支持 html-bodymailto:me@me.com?subject=Me&html-body=<b>ME</b>

泡芙 2020.03.24

值得指出的是,至少在iPhone上的Safari上,似乎确实在body参数中插入了基本的HTML标签,如<b><i><img>(理想情况下,无论如何在其他情况下都不应使用CSS,更喜欢使用CSS)。mailto:工作-他们在电子邮件客户端中很荣幸。我尚未进行详尽的测试,以查看其他移动或桌面浏览器/电子邮件客户端组合是否支持此功能。这是否真的符合标准也值得怀疑。但是,如果要为该平台构建,可能会很有用。

正如其他响应所指出的那样,在将其嵌入mailto:链接之前,还应该在整个主体上使用encodeURIComponent

阳光小胖 2020.03.24

尽管无法使用HTML格式化电子邮件正文,但可以按照先前的建议添加换行符。

如果您能够使用javascript,则“ encodeURIComponent()”可能会像下面这样使用...

var formattedBody = "FirstLine \n Second Line \n Third Line";
var mailToLink = "mailto:x@y.com?body=" + encodeURIComponent(formattedBody);
window.location.href = mailToLink;
凯西里 2020.03.24

有些事情是可能的,但不是全部,例如说您想要换行,而不是使用<br />use%0D%0A

例:

<a href="mailto:?subject=&body=Hello,%0D%0A%0D%0AHere is the link to the PDF Brochure.%0D%0A%0D%0ATo view the brochure please click the following link: http://www.uyslist.com/yachts/brochure.pdf"><img src="images/email.png" alt="EMail PDF Brochure" /></a>                        
小宇宙 2020.03.24

不。这根本不可能。

蛋蛋 2020.03.24

我使用了它,它似乎可以与Outlook一起使用,而不是使用html,但至少可以在将正文添加为输出时使用换行符设置文本格式。

<a href="mailto:email@address.com?subject=Hello world&body=Line one%0DLine two">Email me</a>
西门GO村村 2020.03.24

如您在RFC 6068中所看到的,这是完全不可能的:

特殊的<hfname>“正文”表示关联的<hfvalue> 是邮件的正文。“正文”字段值旨在包含消息的第一个文本/纯文本正文部分的内容。“正文”伪头字段主要用于生成用于自动处理的短消息(例如,用于邮件列表的“订阅”消息),而不是用于一般的MIME正文。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android