14

Chrome's mailto length limit is around 2000 characters. It seems to be enough but in fact it's only enough for English Language. Because the length is calculated after encodeURI.

e.g. for only one Japanese character 'て'. encodeURI('て') gets "%E3%81%A6", which is 9 characters long. So I can only type in around 2000/9 = 200+ Japanese characters in my mail content. This is really too short.

So is there a way to get around this limit? Something like installing chrome plugin is acceptable.

Any suggestion is greatly appreciated.

EDIT

I have finally decided to use a server-side solution: Create a popup page to simulate mail client, with to, cc, subject, content and also a send button. After the user clicks the send button, the form will be submitted and server will send the mail for the user

wander
  • 937
  • 1
  • 7
  • 15
  • 1
    You may have already read this but if your sending your own emails this my provide some useful info to ensure your emails don't end up in the spam folder - http://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/ if your serious about this then some SMTP cloud provider may be of use – SimonGates Jul 29 '14 at 21:18
  • 2
    Good point switching to a server-side solution. As a tip: Be sure to add spam protection by using captchas/rate-limits. Otherwise someone could use your server to send spam to other people and your SMTP server will be blacklisted by common mail providers. (Happend to me a few years ago). – posixpascal Jul 30 '14 at 09:11

3 Answers3

4

I have no problem with any sized mailto-links on a Firefox (Developer Edition 39.0a2, Windows XP), however Internet Explorer 8 and Chrome do not work with mailto-links over the mentioned size of around 2000 characters. So, I doubt it is a Windows specific problem.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Martin
  • 1,112
  • 1
  • 11
  • 31
  • Commenting wasn't possible for me at the time (had less than 25 points) and @progressive_overload edited my mention of this out of my post... – Martin Feb 06 '16 at 14:58
  • @Cyrus when in doubt, don't post an answer at all. – Willi Mentzel Feb 09 '16 at 14:39
  • I am facing exactly same problem. – Lokesh Oct 31 '16 at 21:30
  • I am able to steadily reproduce the problem in Windows/ Chrome, with mailto URL being long anything more than 1580 chars. No matter what is the default email client set up in that Windows machine (tried with Outlook and Thunderbird) – userfuser Feb 02 '23 at 14:31
3

This appears to be a microsoft windows issue. i have tried the following on and it works well with different browsers (safari, chrome 30 & 36, ...) on mac os x.

In windows the request will get truncated to around 2000 characters. this will happen regardless of which browser is being used. it seems windows has a size limit on system uri requests.

I have tried from html <a href="mailto:?body=... and javascript document.location = encodeURI('mailto:?body=' + text) with 100k characters in the message body.

Nick
  • 2,593
  • 3
  • 30
  • 59
dreamlab
  • 3,321
  • 20
  • 23
  • 1
    So it seems not to be chrome's fault. But chrome's encoding strategy for mailto url is really too bad for this OS limit. IE can support roughly 2000/2 = 1000 non-ASCII character while chrome can only support roughly 2000/9 = 200+. – wander Aug 19 '14 at 09:14
2

This question has been posed several times on StackOverflow over the years without an acceptable answer. Server-side solution is NOT always feasible.

The solution below is probably the best way around the problem. The issue in Chrome/Edge is that the "mailto" URL cannot exceed 2000 encoded characters. Therefore, we first test to see if it exceeds 2000 chars, and if it does, copy the "Body" content to the clipboard, and replace original Body with instructions to paste. Note, you may still will run into issues if you have large "To/CC" recipient list.

function invokeMailClient(to,cc,subj,body) {
  let encodedBody = encodeURIComponent(body);
  let mailTo = "mailto:" + to + "?cc=" + cc + "&Subject=" + subj + "&body=";
  if (mailTo.length + encodedBody.length > 1995) {
    copyToClipboard(body);
    encodedBody = encodeURIComponent("** Please press Ctrl-A Ctrl-V    OR Right-Click and Paste the body template for this email **\n");
  }
  window.open(mailTo + encodedBody);
}

function copyToClipboard(str) {
  let el = document.createElement('textarea');
  el.value = str;
  document.body.appendChild(el);
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
};

//TEST IT
let subj = "This is a test subject";
let to="johnDoe@michigan.gov";
let cc="janeDoe@stackoverflow.com";

//let body="small body -- no problem";
//invokeMailClient(to,cc,subj,body);

let body = "A quick brown fox jumps over the lazy dog\r\n".repeat(35); 
invokeMailClient(to,cc,subj,body); //large "body" -- copies to clipboard
Vijay Jagdale
  • 2,321
  • 2
  • 18
  • 16