Reputation: 155
I have a web application that I'm trying to optimize for mobile and my straightforward mailto function isn't working on the default mail client on my Android phone. It works in the gmail client, but not in the native one for integrating with Exchange emails. (It also seems to work on iphones fwiw.) What's happening in the native client is that everything after a carriage return is cut off. So say I have something like the following:
sendLinkByEmail: function (subject, message, url)
{
var parsedMessage = encodeURIComponent("Isn't this cool?\n I am sending you an email!");
var emailLink = "mailto:?Subject=" + encodeURIComponent(subject) + "&body=" + parsedMessage;
window.location = emailLink;
return false;
}
If I choose to open with the Gmail app, I see what I expect:
Isn't this cool?
I sent you an email!
But if I open it with the Mail app, I just get
Isn't this cool?
and that's it.
Same thing happens if instead of \n I use %0A or %0D%0A or if I don't use encodeURIComponent (e.g. the message is just literally "Foo%0D%0ABar"--I just get Foo).
I cannot figure out what that stupid mail client is doing! Anyone have any idea?
Thanks very much!!!
Just realized my problem is even greater--the moronic mail client also truncates anything after even an encoded & (%26) So I can't embed a URL either, which is the whole point of the function.
Is there any alternative to mailto for opening the mail client from a web application?
Upvotes: 2
Views: 2343
Reputation: 24606
In my experience, your success with \n in a mailto: link will vary from mail client to mail client. What I've found to work best is using %0d in place of \n, but even then, not all clients will support it.
If formatting is important to you, a mailto: link is not what you want.
Upvotes: 1