Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mailto fails in IE where there is a long body text. Is there any way to resolve this?

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?

like image 471
MedicineMan Avatar asked Feb 11 '10 00:02

MedicineMan


People also ask

Why is my mailto link not working?

If mailto links don't open for you the way they should, a quick look at the system or browser settings should do the job. In Windows, head to Settings -> Apps -> Default apps. Scroll down and pick “Choose default apps by protocol” from the menu. For 'Mailto', choose the client of your choice.

How do you add body text to mailto?

subject=<subject> to the mailto tag. For example, the complete tag would look similar to the example below. You can also add body text by adding &body=body to the end of the tag, as shown in the example below. You can also include &cc= or &bcc= to fill out the CC and BCC fields.

How do I pass HTML body into mailto?

The Mailto format does not support HTML code emails. Outlook was used at 2003, but to become compliant with the mailto: standard they removed that functionality. But you can Use %0D%0A for a line break in HTML body.


1 Answers

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();
            }
        });
    }
};
like image 51
andrew Avatar answered Oct 18 '22 00:10

andrew