Html Gmail 中的 mailto 链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4708044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:11:49  来源:igfitidea点击:

mailto links in Gmail

htmlemailhyperlinkgmailmailto

提问by sagibb

I've encountered a problem with Gmail's web application. For some reason, the mailtolinks doesn't work when I try to add the body into the link. The links works fine as long as the & separator for the body is not used.

我遇到了 Gmail 网络应用程序的问题。出于某种原因,mailto当我尝试将正文添加到链接中时,链接不起作用。只要不使用正文的 & 分隔符,链接就可以正常工作。

For example:

例如:

href="mailto:?subject=test&body=this is a test"- Doesn't work

href="mailto:?subject=test&body=this is a test"- 不起作用

href="mailto:?subject=testbody=this is a test"- Does work but, obviously, it doesn't generate the desired result as everything goes to the subject.

href="mailto:?subject=testbody=this is a test"- 确实有效,但显然,它不会产生预期的结果,因为一切都与主题有关。

I am running Vista 64bit and I've tried FF, Chrome and IE. Also, I've noticed a difference between how Gmail renders my mail in my Gmail account and Google Apps account.

我运行的是 64 位 Vista,我尝试过 FF、Chrome 和 IE。此外,我注意到 Gmail 在我的 Gmail 帐户和 Google Apps 帐户中呈现我的邮件的方式有所不同。

When i view the same email on my iPhone & Outlook everything seems to work fine.

当我在 iPhone 和 Outlook 上查看同一封电子邮件时,一切似乎都正常。

Any help will be appreciated.

任何帮助将不胜感激。

回答by Mohit Kumar Gupta

The Full mailto Link Syntax For Cross Browser

跨浏览器的完整 mailto 链接语法

<a href="mailto:[email protected]?subject=subject&[email protected]">mail link</a>

Here are the variables you can use in mailto links:

以下是您可以在 mailto 链接中使用的变量:

mailto:to set the recipient, or recipients, separate with comma

mailto:设置收件人或收件人,用逗号分隔

&cc=to set the CC recipient(s)

&cc=设置抄送收件人

&bcc=to set the BCC recipient(s)

&bcc=设置密件抄送收件人

&subject=to set the email subject, URL encode for longer sentences, so replace spaces with %20, etc.

&subject=设置电子邮件主题,为更长的句子进行 URL 编码,因此用 %20 等替换空格。

&body=to set the body of the message, you can add entire sentences here, including line breaks. Line breaks should be converted to %0A.

&body=要设置邮件正文,您可以在此处添加整个句子,包括换行符。换行符应转换为 %0A。

Some mailto link examples

一些mailto链接示例

<a href="mailto:[email protected][email protected]&[email protected]&subject=Subject Using Mailto.co.uk&body=Email Using Body">Email-Link</a>

Multiple Recipients:

多个收件人:

<a href="mailto:[email protected],[email protected],[email protected]">Contact Us</a> 

Online Generation Link: http://www.mailto.co.uk/

在线生成链接http: //www.mailto.co.uk/

回答by Michaelp

I can get everything to populate on the gmail interface using their full url:

我可以使用他们的完整 url 在 gmail 界面上填充所有内容:

https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&[email protected]&subject=MISSED%20CALL%20EZTRADER&body=Hello%2C%0A%0AI%20tried%20contacting%20you%20today%20but%20you%20seem%20to%20have%20missed%20my%20call.%20%0A%0APlease%20return%20my%20call%20as%20soon%20as%20you%E2%80%99re%20available.%20%0A%0AIn%20any%20case%2C%20I%20will%20try%20ringing%20you%20at%20a%20later%20time.%0A%0A%0ATy%2C%0A%0A%0A%0A

But I still can't get the subject line to populate. I am still investigating, if anyone has an answer or knows the gmail encoding ref on the url for it?

但我仍然无法填充主题行。我仍在调查,是否有人有答案或知道 url 上的 gmail 编码参考?

回答by dantj

Try href="mailto:?subject=test&body=this+is+a+test"

尝试 href="mailto:?subject=test&body=this+is+a+test"

回答by Xmagic

dude , even if I didn't encoding '&', however I replace followings characters, and then pass the email body and subject to mailto, it does work for me. Hope this may brings you some ideas.

伙计,即使我没有编码'&',但是我替换了以下字符,然后传递电子邮件正文并以mailto为主题,它对我有用。希望这能给你带来一些想法。

body = body.replaceAll("\\", "%5C");
body = body.replaceAll(" ", "%20");
body = body.replaceAll("\r", "%0D");
body = body.replaceAll("\n", "%0A");
body = body.replaceAll("\t", "%09");

回答by m93a

Tested in Firefox 19 - working.
In Chrome you need to install an extension to get it working.

在 Firefox 19 中测试 - 工作正常。
在 Chrome 中,您需要安装一个扩展程序才能使其正常工作。

The page I tested - https://dl.dropbox.com/u/60854445/mail.html
Chrome extension - https://chrome.google.com/webstore/detail/mailto-for-gmail/dgkkmcknielgdhebimdnfahpipajcpjn/

我测试的页面 - https://dl.dropbox.com/u/60854445/mail.html
Chrome 扩展 - https://chrome.google.com/webstore/detail/mailto-for-gmail/dgkkmcknielgdhebimdnfahpipajcpjn/

Maybe they have fixed it.

也许他们已经修复了它。

回答by Mike Van Stan

As you can see in RFC 2368, this is not possible at all:

正如您在RFC 2368 中看到的,这根本不可能:

The special hname "body" indicates that the associated hvalue is the body of the message. The "body" hname should contain the content for the first text/plain body part of the message. The mailto URL is primarily intended for generation of short text messages that are actually the content of automatic processing (such as "subscribe" messages for mailing lists), not general MIME bodies.

特殊的 hname "body" 表示关联的 hvalue 是消息的正文。“body” hname 应包含消息的第一个文本/纯正文部分的内容。mailto URL 主要用于生成实际上是自动处理内容的短文本消息(例如邮件列表的“订阅”消息),而不是一般的 MIME 正文。

回答by Vishal

try this
<a href="mailto:[email protected]?subject=SweetWords&body=Please send me a copy of your new program!">Email Me</a>

回答by Kurly Fisher

Consider swapping the spaces for %20. Also, what is the formatting problem? Or better clarity in all would be helpful. you said "the mailto links doesn't work" and "Gmail renders my mail in my Gmail account and Google Apps account". Is it sending it or not, and if it's sending to both what specifically is the difference.

考虑交换 %20 的空格。另外,格式问题是什么?或者更好的清晰度会有所帮助。您说“mailto 链接不起作用”和“Gmail 在我的 Gmail 帐户和 Google Apps 帐户中呈现我的邮件”。是发送还是不发送,如果发送给两者,具体有什么区别。