0

My application sends an HTML email with a hyperlink. The user should be able to click on the link in a mail client and the browser opens the page. Easy... i thought.

But now the link contains special characters in a query param. E.g. the value for the second query param is id=1234/pid=1000 and the resulting java.net.URLEncoder.encode()d URL becomes

http://example.com/path/?key1=value1&key2=id%3D1234%2Fpid%3D1000

And this is what gets embedded into an HTML mail:

<html ...
<head>
<meta http-equiv=Content-Type content="text/html; charset=unicode">
...
<body lang=EN-US ...
<a href="http://example.com/path/?key1=value1&ampkey2=id%3D1234%2Fpid%3D1000">link text</a>
...

(at least this can be seen in the raw mail content by the receiving client).

Problem is that when clicking on the link, the browser opens up but the query params are double encoded: http://example.com/path/?key1=value1&key2=id%253D1234%252Fpid%253D1000

and the link does not work anymore. Funny thing, if the link is copy/pasted into the browser, the additional encoding is omitted (as expected). When hovering over the link with the mouse, the URL is displayed decoded: http://example.com/path/?key1=value1&key2=id=1234/pid=1000 (tested with Outlook and Thundbird, both have same behaviour).

So my question is, what is wrong here?

  • Is it my first encoding and should I skip it?
  • Is it my first encoding and am I doing it wrong?
  • Are the mail clients to blame?

I can find tons of information about how URL encoding works and that it should be done but not which encoding in which use cases. Thanks.

ABika
  • 597
  • 1
  • 5
  • 11

1 Answers1

0

Finally solved it. It has nothing to do with the encoding in the mail or the mail client but the server does an instant redirect and changes the query parameter -> duplicate of mod_rewrite urlencoding an already urlencoded query string parameter - any way to disable this?.

Should have really tried example.com to figure this out but I couldn't even imagine it's a problem with the web server.

ABika
  • 597
  • 1
  • 5
  • 11