-1

I'm trying to open the local mail window using the javascript window.location.href=mailto:<addresses>. However, my addresses exceed the maximum length. So I slice it into pieces, and send these one after the other, after a specific timeout. However, the second relocation will not open a new (Outlook) mail window if the first is still open... Is there any way to get around this? Or is there another/better way to open multiple mail windows on the local client?

Any help would be greatly appreciated!

The code:

function Send_Mails(mails) {

var timeout = 2000;
var maxUrlCharacters = 1900;
var currIndex = 0;
var nextIndex = 0;

if (mails.length < maxUrlCharacters) {
    window.location = 'mailto:' + mails;
    return;
}

do {
    currIndex = nextIndex;
    nextIndex = mails.indexOf(';', currIndex + 1);
} while (nextIndex != -1 && nextIndex < maxUrlCharacters)

if (currIndex == -1) {
    window.location = 'mailto:' + mails;
} else {
    window.location = 'mailto:' + mails.slice(0, currIndex);
    setTimeout(function () {
                Send_Mails(mails.slice(currIndex + 1));
                }, timeout);
}

}

This opens the first mailwindow correctly, but the second one is never opened as long as the first one is open.

Best regards, Hans

Hans
  • 1
  • 3

1 Answers1

0

The sample script below works for me on localhost

<button onclick="openmail()">Open mail</button>
<script>
    function openmail(){
        window.location.href="mailto:test1@test.org"
        setTimeout(function(){
            console.log('2nd email');
            window.location.href="mailto:test2@test.org"
        }, 3000);
    }
</script>

When on Fiddle, it seems to be working 75% of the time (with ad blocker turned on).

There is a risk that popup and ad blockers, anti-virus software etc. may silently block forced opening of multiple mailto links.

EnigmaRM
  • 7,523
  • 11
  • 46
  • 72
  • Thanks for the tip about the popup blockers, any idea where and how I could best check this? – Hans Jun 16 '16 at 06:10
  • Try removing your popup blockers and checking your browser's settings for popups. But the important thing to keep in mind, you won't be able to do this on your client computers. You may want to consider a different implementation if this needs to be distributed to clients. – EnigmaRM Jun 16 '16 at 14:38