javascript - Mailto link not copying body of email on Chromebook - Stack Overflow

I'm generating a mailto: link that also contains the body of an email. I'm opening the link u

I'm generating a mailto: link that also contains the body of an email. I'm opening the link using JavaScript to launch the mailto: client of the OS. On Chromebooks the link opens Gmail with the email address, but not the body of the email. This is the link:

var MailToLink = 'mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck.'

This is the line I use to open the link: window.open(MailToLink, '_blank');

It works just fine on Windows 10 OS with Thunderbird and Gmail for Android.

Is there something I need to change for Chromebooks?

I'm generating a mailto: link that also contains the body of an email. I'm opening the link using JavaScript to launch the mailto: client of the OS. On Chromebooks the link opens Gmail with the email address, but not the body of the email. This is the link:

var MailToLink = 'mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck.'

This is the line I use to open the link: window.open(MailToLink, '_blank');

It works just fine on Windows 10 OS with Thunderbird and Gmail for Android.

Is there something I need to change for Chromebooks?

Share Improve this question edited Jun 14, 2019 at 16:02 Douglas Reid 3,8186 gold badges33 silver badges50 bronze badges asked Jun 5, 2019 at 17:39 frenchiefrenchie 52.1k117 gold badges320 silver badges528 bronze badges 8
  • 2 using anything but _self creates fork bomb for my beta channel chromebook, but with _self the body shows up (with a little delay) for me. I would test with _self to make sure its not an interaction with popup/security features. But also you can try deleting gmail from chrome://settings/handlers and record the unhandled url in the broken tab it creates before letting gmail reregister to see which stage is dropping the body. – lossleader Commented Jun 14, 2019 at 14:14
  • Thanks. I'll try it and let you know how this works. – frenchie Commented Jun 14, 2019 at 15:49
  • @frenchie any updates on how lossleader's solution went? – Dakota Maker Commented Jun 15, 2019 at 2:43
  • On Monday I will – frenchie Commented Jun 15, 2019 at 16:25
  • The problem is that _self doesn't work in terms of UX. The email needs to be processed in another tab with the current tab not changing URL. – frenchie Commented Jun 16, 2019 at 18:22
 |  Show 3 more ments

4 Answers 4

Reset to default 3 +200

What about setting location.href instead of creating a popup?

location.href = "mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck."

Looking for an answer drawing from credible and/or official sources.

Good to know is that subject and body in mailto links are described in RFC 2368 - The mailto URL scheme

Clients that resolve mailto URLs into mail messages should be able to correctly create RFC 822-pliant mail messages using the "subject" and "body" headers.

Please also note there is a paragraph over "unsafe headers" - so I think the content could be also important.

  1. Unsafe headers

    The user agent interpreting a mailto URL SHOULD choose not to create a message if any of the headers are considered dangerous; it may also choose to create a message with only a subset of the headers given in the URL. Only the Subject, Keywords, and Body headers are believed to be both safe and useful.

Try this

var MailToLink = 'mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck.'
var sendEmail = document.getElementById('sendEmail');

  sendEmail.addEventListener('click', function (e){
    window.location.href = MailToLink;
  });
<input type="button" id="sendEmail" value="submit">

Another stable option is to a <a> and edit the href with javascript.

e.g.

var mailto = "mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck."

document.getElementById("myLink").setAttribute("href", mailto)
<html>
<body>
    <a id="myLink">Create email now!</a>
</body>
</html>

Not sure if this fits in your requirements.

The easiest thing to do might be to use the classic mail to link using an anchor tag, however, I am guessing you are using JavaScipt for a specific reason so maybe if you specify a simple name as the second argument rather than one of the '_blank' or '_self' values. for example, you could call it 'emailWindow' or something like that.

Here is the is the MDN link that inspired using the window name: https://developer.mozilla/en-US/docs/Web/API/Window/open#Parameters

and here is some code below to test it out.

*Note: For security reasons I believe StackOverflow has disabled the ability to open a new window so you will have to test the button code locally, sorry

var MailToLink = 'mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck.'

const sendEmailButton = document.getElementById('sendEmailButton');
sendEmailButton.onclick = () => {
    window.open(MailToLink, 'emailWindow');
    if (window.open && !window.closed) {window.close();}
};
<h1>Anchor Tag and Button Versions of Mail To</h1>

<h2>The anchor tag version</h2>
<a href="mailto:[email protected]?subject=Test%20Email%20Subject&body=Great,%20the%20mailto%20protocol%20works%20and%20you%27re%20good%20to%20go.%20Good%20luck.">test mail to using href</a>


<h2>the button version</h2>
<button type="button" id="sendEmailButton">test mail to using button</button>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745377401a4625063.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信