20
votes

I've encountered a problem with Gmail's web application. For some reason, the mailto links 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.

For example:

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

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.

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.

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

Any help will be appreciated.

9
What happens when you use & instead of &? - Alec
Same thing, I've tried & %26 and &amp/ but they all produced the same result. - sagibb
mailto: links with parameters are a non-standardized, unreliable thing in the first place. I wouldn't be surprised if there are more applications other than GMail out there that doesn't support them properly (maybe even on purpose due to security concerns). I would avoid them and look for more reliable solutions to your objective. - RoToRa

9 Answers

15
votes

The Full mailto Link Syntax For Cross Browser

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

Here are the variables you can use in mailto links:

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

&cc= to set the CC recipient(s)

&bcc= to set the BCC recipient(s)

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

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

Some mailto link examples

<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/

8
votes

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

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?

1
votes

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.

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

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

1
votes

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

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

Maybe they have fixed it.

1
votes

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

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.

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

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.

0
votes

I was struggling to find out why &subject= doesn't work in href for Gmail.


So I found this &su= to make subject work.

See example below:

href="https://mail.google.com/mail/?view=cm&fs=1&tf=1&to={{[email protected]}}&su=Subject&body=Body%20Text"

%20 - space

%0A - new line