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?

Andrew Magill
  • 2,254
  • 4
  • 21
  • 28

4 Answers4

3

In IE 8 its an setting option. Tools -> Options -> Advanced. Under International check the option "Use UTF-8 for mailto links".

Under Windows XP this setting is disabled by default. Under Windows 7 its enabled by default.

Hope this helps

Daniel
  • 31
  • 2
2

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:your@email.com?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
  • 74,484
  • 29
  • 137
  • 169
  • 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 Sep 24 '09 at 15:49
  • 3
    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 Sep 24 '09 at 15:51
  • 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 Sep 24 '09 at 16:30
  • 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. – Andrew Magill Sep 24 '09 at 16:36
  • 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 Sep 24 '09 at 16:39
  • 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#anchor2 It states that 8-bit encoded characters in mailto's are forbidden. – Andrew Magill Sep 24 '09 at 16:53
  • With MIME encoding, you can't never header correctly. See my edit. – ZZ Coder Sep 24 '09 at 17:12
  • That comment is totally wrong :) Should be: Without MIME encoding, you can never get header correctly. – ZZ Coder Sep 24 '09 at 17:14
  • @ZZ Coder Nope. with your example, its simple shows your ISO parameter instead of the subject. – Andrew Magill Sep 24 '09 at 17:38
  • 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 Sep 24 '09 at 17:42
  • 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 Sep 24 '09 at 17:49
  • @ZZ Coder You 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. – Andrew Magill Sep 24 '09 at 22:03
  • Yes. It works for me. Try a different mail client. Post your mail headers if you still have issues. – ZZ Coder Sep 25 '09 at 01:41
1

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
  • 159,146
  • 25
  • 197
  • 199
  • I think you are right, see the link in my comment above. It seems that there is no specified operation on the side of the email reader in the URL spec. Mail.app, may have just gone 'above and beyond' for the sake of international usability. But if Outlook 2007 can't do this, its not reliable enough to put into production. Unless I hear about a magic &charset=UTF-8 parameter, this one is dead. – Andrew Magill Sep 24 '09 at 17:00
  • A more detailed post is here: http://stackoverflow.com/questions/974558/outlook-not-processing-multi-byte-characters-when-using-mailto – Andrew Magill Sep 24 '09 at 17:03
1

For example, with mootools (but could be another framework or even 'raw' javascript), I usually do this, and it works mac/pc with the main browsers/clients:

window.addEvent('domready', function(){
    //get the links to encode
    var links_to_encode = $$('#page ul li a');

    links_to_encode.each(function(link){
        //check if the link has an href
        var original_href = link.get('href');
        if(original_href){
            //substitute it with the encoded version
            link.set('href',encodeURI(original_href));
        }
    });
});//fine domready

Bye!

Luca Reghellin
  • 7,426
  • 12
  • 73
  • 118