mailto special characters
Asked Answered
S

10

19

Is there a way to make the email client ( Outlook ) accept special characters coming from the mailto link in html? I'm trying to have a mailto link with german characters in the body, but in Outlook I get only strange characters.

Thanks

Stepsister answered 12/6, 2009 at 15:12 Comment(1)
I have the same problem. Can you pick an aswer or post your own?Frill
C
22

I just spent 2 days investigation this issue. Our issue was that mailto: links on our utf-8 encoded web pages did not work for Outlook users if the subject= string contained non-ascii characters, like e.g Norwegian characters. An example is: "mailto:[email protected]?subject=julegløgg og fårikål"

From what I have learned so far, Outlook simply does not handle anything other than ASCII and iso-8859-1 characters. So when trying to click on the above mailto link (either from IE or Firefox), Outlook fails to decode the characters, leaving the subject broken and containing "weird" characters.

So the next step was to try to re-encode the pages in ISO-8859-1. What we did was to replace the original mailto link on the utf-8 page with a link to a "email-to-iso"-service, like this:

http://url.com/service.php?service=util.mailtoencode&mailto=mail%40coretrek.no%3Fsubject%3Demne+%C3%B8%C3%A6%C3%A5+emne

This page would convert the mailto characters to iso-8859-1 and then output the entire page content in iso-8859-1. A javascript on the page, containing "location.href='mailto:...'" was used to open the client's email client automatically.

So far everything seemed ok. This actually works in Internet Explorer, both with Thunderbird and Outlook (tested on IE7 on WinXP with Outlook express and TB 2).

BUT the problem now is actually Firefox. It seems like Firefox is unable to decode url-encoded urls containing characters found only in ISO-8859-1 but not in ASCII (like the norwegian å, represented by %E5 when encoded). The same å is handled correct if the page encoding is utf-8, but it seems like the Firefox developers have forgotten to test special characters together with the ISO-8859-1 charset. The result is that Firefox passes an un-decoded string (still containing %E5 intstead of å) to the email client. And, amazingly, this is handled correct by Outlook (which manages to decode the string itself), but NOT by Thunderbird, which probably has the same bug as Firefox. If you DON't url encode the subject, the string is passed correctly to Thunderbird, but not to Outlook.

We have also been trying other encoding methods, like php's htmlentities, htmlspecialchars, base64 encoding etc, but all of them fails one way or the other.

So, summarized:

Pages encoded in utf-8:

IE fails always

FF -> Thunderbird: OK

FF -> Outlook: FAIL

Pages encoded in iso-8859-1:

IE: OK

FF -> Thunderbird: Fails if subject is url encoded, ok if not)

FF -> Outlook: Fails if subject is not url encoded, ok if encoded) (this is Windows, on Ubuntu Linux FF and TB works OK always).

Hoping this was helpful for others having the same problem.

Conscription answered 2/12, 2009 at 8:23 Comment(0)
L
10

In PHP I think the function that works best with Outlook is rawurlencode()

Lycurgus answered 11/5, 2010 at 17:33 Comment(2)
I just figured this out myself, after trying all sorts of other methods. +1Skiascope
Works like a charm :-)Nittygritty
C
4

I think using a urlencode method should do what you're looking for. JavaScript has .encodeURI() methods on string objects, and .NET has the HttpUtility.UrlEncode method.

What language are you using?

Columbic answered 12/6, 2009 at 15:43 Comment(1)
I am using UrlEncode with Razor. U have any idea about this @John? #33098143Unwished
F
3

Actually, the solution is http://blogs.msdn.com/ie/archive/2007/02/12/International-Mailto-URIs-in-IE7.aspx and it is not nice.

Basically, in IE 7 and 8 the user must have enabled an advanced setting in Internet Options, something that 100% of the users will not know will not have enabled.

Fidellia answered 26/2, 2010 at 14:58 Comment(0)
P
2

You need to enable UTF-8 support for the mailto: protocol

From the main outlook window, click Tools -> Options -> mail format -> international options -> "Enable UTF-8 support for mailto: protocol".

Pluck answered 31/1, 2011 at 2:11 Comment(1)
Alas, when you're designing a site that may need special characters in mailto:, you don't have control over the configuration of the various people you hope will click the link.Verso
F
2

rawurlencode() function works best with outlook, tested with Firefox, Chrome & IE

Flyleaf answered 11/11, 2011 at 7:14 Comment(1)
This is the same answer as that provided by Mario Chueca in 2010.Newark
V
1

As yandr indicated, this issue is an ongoing problem with Outlook.

Microsoft has published documentation that states that properly configured Outlook 2003 and 2007 attached to a properly configured Exchange server will default to supporting Unicode, but that doesn't really help you with the general public.

For reference, the "standard" you want to refer to for this is RFC 2047.

The solution that I have implemented to get around this limitation (with Swedish, actually) is to use a web form instead of a mailto: link. It requires more setup on the server side, but gives you a lot more control over the contact process.

I'm sure this isn't what you wanted to hear, but until the world stops using broken software from Microsoft, we'll continue to need workarounds like this.

Verso answered 7/12, 2011 at 22:55 Comment(0)
Y
0

It sounds like you need the page containing the mailto link to be in the encoding that Outlook is expecting. Without knowing any more about the situation, I'd try encoding the page in UTF-8 and ISO-8859-1.

The relevant 'more about the situation' would be what weird characters appear and what the page's encoding is currently.

Yokum answered 12/6, 2009 at 15:16 Comment(0)
G
0

If one is using SharePoint 2010, it seems Microsoft has been aware of this issue, and has supplied some functions to solve this.

The following will properly escape the link to the current page

escapeProperly(escapeProperlyCoreCore($(location).attr('href'), false, false, true))

Gezira answered 7/3, 2013 at 15:56 Comment(0)
I
0

In JavaScript you can use encodeURIComponent function for subject and body. Then it will show all special characters in email.

const emailRequest = {
    to: "[email protected]",
    cc: "[email protected]",
    subject: "Email Request - for <CompanyName>",
    body: `Hi All, \r\n \r\n This is my company <CompanyName> 
            \r\n Thanks`,
};

const subject = encodeURIComponent(emailRequest.subject.replace("<CompanyName>", 'ABC & ** Company'));
const body = encodeURIComponent(emailRequest.body.replace("<CompanyName>", 'ABC & ** Company'));
window.location.href = (`mailto:${emailRequest.to}?cc=${emailRequest.cc}&subject=${subject}&body=${body}`);
Insouciance answered 22/11, 2019 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.