15

I am having a problem using Internet Explorer 8 (IE8) to open mailto links with long messages.

After the user clicks on the link, IE changes to an about:blank page and never completes the call to outlook to create an email

Here's an example:

<a href="mailto:[email protected]?subject=123456789&amp;body=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111">mailto fails in IE8</a>

If I shorten the list of 1's, the email is generated and can be sent.

Is this a known IE issue? What are the limitations?

3
  • 4
    those IE guys are jerks Sep 3, 2014 at 7:22
  • 1
    I agree, and on IE11 mailto still fails when body is too long. Jan 30, 2015 at 13:41
  • This post is 9 years old now. I can't believe people are still looking at it. Aren't there better solutions yet???? Mar 11, 2019 at 23:52

5 Answers 5

32

I never could get the location.href = mailtoHref hack to work. However, I have found that following works.

$('body').append($('<iframe id="mailtoHack" src="' + mailtoHref + '"/>');
$('#mailtoHack').remove();

EDIT

Here is a way to do it without jQuery:

function mailtoHack(href) {
    var iframeHack;
    if (href.indexOf("mailto:") === 0) {
        iframeHack = document.createElement("IFRAME");
        iframeHack.src = href;
        document.body.appendChild(iframeHack);
        document.body.removeChild(iframeHack);
    }
}

And, for good measure, here is a Knockout custom binding usable as data-bind="mailto: foo":

ko.bindingHandlers.mailto = {
    init: function (element, valueAccessor) {
        ko.utils.registerEventHandler(element, "click", function (e) {
            var href = ko.unwrap(valueAccessor()), iframeHack;
            if (href.indexOf("mailto:") === 0) {
                iframeHack = document.createElement("IFRAME");
                document.body.appendChild(iframeHack);
                document.body.removeChild(iframeHack);
            } else {
                e.preventDefault();
            }
        });
    }
};
6
  • 5
    Genius. I am working on a corporate intranet that has all sorts of bizzare modifications to IE 7. This hack defeats their mods and makes my client happy! Thanks!
    – Kevin
    Oct 5, 2012 at 17:38
  • 1
    IMO this should be the answer - the one above gives me the same issues as a straight-up mailto, but this solves it.
    – Matthew
    Nov 22, 2013 at 15:25
  • 1
    This hack is fairy powder, it works also in IE11. IE is a model of unsoundness! Jan 30, 2015 at 15:05
  • Using this in FF the mailto URL is still clipped but at 1963-1965 characters (again, no rhyme or reason as to what the exact number is). With this solution the user sometimes does not suspect that his email is not going to reach some of the addressees unless the email client alerts them to a corrupt address. This may clip the addresses at the domain suffix. And the long mailto: does not work in Opera.
    – ajeh
    Mar 25, 2015 at 15:07
  • 2
    Your jQuery's first line is missing a )
    – jehna1
    Apr 29, 2015 at 12:15
12

I too ran into this problem with IE8. Amazing that this is happening; it seems like a problem we'd have run into circa 1998!

Anyway, I did some testing and came up with a workaround that uses Javascript:

<a href="javascript:doMailto()">Send Email</a>

Then define this script:

<script type="text/javascript">
   var sMailto = "mailto:[email protected]?subject=123456789&amp;body=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111234567890";

   function doMailto() {
      document.location.href = sMailto;
   }

</script>

For whatever reason, IE has no problem "forwarding" to long URLs (my testing scenario uses 800+ characters). In cases with multiple mailto links, you could define multiple URL variables and send a parameter into doMailto() that lets it switch to the appropriate one.

Is it ugly? You bet. But it works in a pinch.

5
  • 3
    FWIW, I consistently had problems with URLs longer than ~505 characters. So even 512 doesn't seem like a hard-and-fast rule. Thanks, IE8!
    – CBono
    Jul 19, 2010 at 18:09
  • 1
    After a lot of testing it seems that it tops out at exactly 509. For me at least.
    – Jeff
    Feb 10, 2011 at 18:36
  • 1
    Hmm odd, Ive encountered a limit at 531, while using a javascript solution like yours
    – Andreas
    May 21, 2014 at 14:45
  • 4
    On IE11, this does NOT work when URL is longer than 507 characters. Jan 30, 2015 at 15:03
  • There seems to be no rhyme or reason as to what is the exact length of mailto: URL that would or would not work. I am facing the same issue in IE9 simply sending to multiple addresses (not using Subj or Body) and the solution in the answer does not work.
    – ajeh
    Mar 25, 2015 at 14:47
2

My advice would be to stop abusing the poor mailto link. If you want to prepopulate that much information, build a contact form for the user.

0
2

I also tried with the solution CBono posted but I coudn't make it work either. I found that when you directly paste the mailto URL in the browser it has no problem no matter how long the string is. So, I implemented something like this:

<a href ="#" onclick="javascript:doMailto(); return false;">Send Email</a>

<script type="text/javascript">
   var sMailto = "mailto:[email protected];[email protected];[email protected]?subject=A really long subject can go here if you want and it will work Im telling you&body=Click for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profile&cc= &bcc= [email protected]";

   function doMailto() {
      window.open(sMailto);
   }

</script>

As CBono mentioned, if you want this to be dynamic, you just need to pass the mailto string as parameter to the function and assing it to the sMailto variable.

Hope this helps.

1

it appears that the following hyperlink seems to work. It is 512 characters long and seems to work every time. You can increase the length of the To, but you must subtract either from subject or body. Same with subject.

I wish this was documented somewhere; I am just guessing from experimenting with this.

<a href="mailto:[email protected]?subject=123456789&amp;body=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111234">

I will gladly accept any answer from a person that can track down documentation that indicates that this is a known issue.

1
  • 512 is a rather odd number. 2038 is the longest legth that IE supports for URLs, but 512 makes that really weird
    – Earlz
    May 20, 2010 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.