Mailto link not copying body of email on Chromebook
Asked Answered
L

4

10

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?

Linder answered 5/6, 2019 at 17:39 Comment(8)
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.Stow
Thanks. I'll try it and let you know how this works.Linder
@Linder any updates on how lossleader's solution went?Heterochromous
On Monday I willLinder
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.Linder
Does rearranging the parameters in the mailto link provide any different results?To
I'm pretty sure that (some) Chromebooks don't have a great processing power. So, it might not be possible and if it is possible, I wouldn't know how to solve the problem.Soothfast
Please tell use why the javascript is needed and not a <a> and could the user click on a link/button before creating the email?Waltz
W
3

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-compliant 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.

Waltz answered 21/6, 2019 at 18:38 Comment(0)
A
2

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">
Abusive answered 21/6, 2019 at 18:47 Comment(0)
W
1

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.

Waltz answered 21/6, 2019 at 18:51 Comment(0)
S
0

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.org/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>
Sizar answered 19/6, 2019 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.