4

I am trying to use mailto function for getting the outlook window in my web application, using the below code.

<a href="mailto:myemail@gmail.com?body=**bodyText**">Send mail</a>

It works fine if the bodyText is less than around 1800 characters. But it truncates the data beyond 1800 characters. If the body content is more that 1800 outlook window just displays 1800 characters and truncate the remaining content.

  • I'd wager this has to do with URL length limits. That can vary wildly from browser to browser (can't remember off the top of my head actual figures, unfortunately). So two things - which browser are you using / targeting, and out of curiosity why would you need a predefined email text that large in a link (I can't think of a reason)? – Xeren Narcy Jun 17 '16 at 00:24
  • This should help re URL length limits - http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers – Xeren Narcy Jun 17 '16 at 00:33
  • I am using both Chrome and Firefox. Its a client requirement to use mailto (They just want to preview body, and make necessary updated before sending it to Others) – Ramachandra Reddy Jun 17 '16 at 00:33
  • I can't reproduce this with Chrome 51 on OS X. I was able to use a link with 4000 characters in the body and they all showed up in the mail. – Barmar Jun 17 '16 at 00:46
  • @Barmar I am using Windows 10 and Ubuntu14.04. – Ramachandra Reddy Jun 17 '16 at 00:48
  • Are you URL-encoding the body text correctly? – Barmar Jun 17 '16 at 00:52
  • @Barmar Yes. I am using encodeURIComponent(bodyText). – Ramachandra Reddy Jun 17 '16 at 01:15
  • This question has been posed several times on StackOverflow over the years without an acceptable answer. Server-side solution may be feasible for everyone. I posted a solution here https://stackoverflow.com/a/74778578/3297640 – Vijay Jagdale Dec 12 '22 at 23:56

1 Answers1

3

First I would refer to this as to why the URL length limit exists. I have tried a quick test using latest Firefox and Outlook 2010 using this

<html>
<body>
<form action="mailto:me@me.com">
<textarea name="body"></textarea>
<br/>
<input type="submit" />
</form>
</body>
</html>

In my case the limit was 2061 characters, but that would be traded off against the email length. Even using POST method the result is the same for me.

The linked question (and its top answer) advise not to rely on lengths longer than 2000 as of April 2016 for the reasons listed.

getting around this

I can suggest a couple directions to explore as an alternative.

  1. Using scripting to invoke Outlook. I don't like it (compatibility, safety) but this may be the one time ActiveX might be a solution.
  2. If the aim is to preview an email, edit, and send, you may consider writing the application to send a draft copy of the email from the server end.

Personally I would explore #2 over #1. In that solution the user would receive an email containing the draft message, which they can edit and forward, or copy into a new email. It's not ideal but it might do for your requirements.

Community
  • 1
  • 1
Xeren Narcy
  • 875
  • 5
  • 15