views:

1094

answers:

2

I'm trying to create a mailto link that contains french accented characters as the subject and email body. Both HTML and URI encoding the chars does not work. Here is my code:

<a href="mailto:%20?subject=ce%20titre%20est%20cass%C3%A9.&body=travaux%20deja!%20cesser%20d'%C3%AAtre%20t%C3%AAtu">SEND EMAIL</a>

Same result occurs without URI encoding:

<a href="mailto:?subject=ce titre est cassé&body=travaux deja! cesser d'être têtu">SEND EMAIL</a>

No Matter how i do it, the new email opens up with the broken characters. URI encoded Spaces and line-breaks work fine, but anything that is not ANSI is broken. I should note that I am testing in both english and french versions of MS Outlook 2007. Anyone know how to get this to work?

A: 

Everything in mail header (including subject) must be MIME-encoded according to this RFC,

http://www.ietf.org/rfc/rfc2047.txt

It's not trivial to do this but you can find code to handle it in most languages.

The properly encoded text looks like this,

=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=

EDIT: Try this to see if it's what you want,

<a href="mailto:[email protected]?subject=%3d%3fISO-8859-1%3fB%3fY2UgdGl0cmUgZXN0IGNhc3Pp%3f%3d&Content-Type=text%2fplain%3b+charset%3dISO-8859-1&body=travaux%20deja!%20cesser%20d'%C3%AAtre%20t%C3%AAtu">SEND EMAIL</a>

Replace email with your address.

ZZ Coder
The OP is not forming an email in this example. He's forming a mailto link. That spec has nothing to do with his context.
Asaph
Please read RFC before you downvote. This RFC is about headers, not mail bodies. The Subject must be encoded like this to show up correctly in mail agent.
ZZ Coder
I believe that is the responsibility of the email agent, not the html page. If you encoded it in the html page too, I think you would end up with a doubly encoded string.
Asaph
I really think ZZ Coder is onto something regarding mime types. But Asaph is correct, this doesn't answer my question. How can I change a mimetype from a mailto link? I'm not sure its possible.
Armitage
What is the mime-type of your html page? you can specify a charset for the whole page like this: Content-Type: text/html; charset=UTF8
Asaph
Im using UTF-8 on the page which shows everything fine. The page shows accented chars normally. I've found more detail on this here:http://xml.resource.org/public/rfc/html/rfc2368.html#anchor2It states that 8-bit encoded characters in mailto's are forbidden.
Armitage
With MIME encoding, you can't never header correctly. See my edit.
ZZ Coder
That comment is totally wrong :) Should be: Without MIME encoding, you can never get header correctly.
ZZ Coder
@ZZ CoderNope. with your example, its simple shows your ISO parameter instead of the subject.
Armitage
I tested ZZ Coder's edit. As I anticipated, the subject line in Entourage shows the literal "ISO..." and also still mangles the body. Impressively though, Mail.app parses it and shows the subject line and body correctly.
Asaph
I tried in Outlook, Entourage, Web Gmail and they all look correctly. We get customer support Email from our web site like this all the time with Chinese and most mail agent handles it correctly.
ZZ Coder
@ZZ CoderYou tried YOUR link, the same as in your answer, and it works for you?!? It doesn't for me and it also doesn't seem to work for Asaph. I would live to see a working example of this.
Armitage
Yes. It works for me. Try a different mail client. Post your mail headers if you still have issues.
ZZ Coder
A: 

Got it! This may or may not be a bug in Microsoft Outlook/Entourage. I changed my default mail reader to Mail.app and it works beautifully with urlencoding. The (maybe) bug only appears to affect one of the 2 accented e characters in your example. Perhaps Outlook/Entourage is not handling miltibyte UTF8 chars correctly?

Asaph
Armitage
A more detailed post is here: http://stackoverflow.com/questions/974558/outlook-not-processing-multi-byte-characters-when-using-mailto
Armitage