Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook strips URL hash from email

Our app generates an email that includes a link with a hash fragment.

  • When an Outlook 2010 user clicks the HTML link (within the <a> tag), the URL is opened but mysteriously excludes the hash fragment.
  • If the user clicks the plain URL (that Outlook converts to a clickable link), the full URL opens correctly.

Here is the relevant code from our Rails app, if that helps:

mail(from: @message.from, to: @message.to, cc: @message.cc, bcc: @message.bcc, subject: @message.subject) do |format|
  format.html { render text: @message.body_text }
end

Email message (truncated; using Twitter URLs in place of our app URLs, which follow a similar pattern):

Subject: Hello
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content='text/html; charset=utf-8' http-equiv='content-type'>
    <title>title</title>
  </head>
  <body>
    <table id='message_body_template'>
      <tr>
        <td>
          <p><a href="http://twitter.com/#!/cnn" title="" target="">Click here</a> 
             to learn more.</p>
          <p>Plain text link: http://twitter.com/#!/cnn</p>
        </td>
      </tr>
    </table>
  </body>
</html>

Click here opens the Twitter home page, while the plain text "link" opens CNN's Twitter page. Can anyone explain why?

like image 270
Martin Gordon Avatar asked Nov 14 '22 08:11

Martin Gordon


1 Answers

Yes, the problem is unrelated to what back-end you use. It appears that (frustratingly) some versions of Outlook strip the hash portion of URLs.

My solution was to email a modified version of the link without the hash, and then redirect it to where it's supposed to go.

When I had the same issue in Laravel + Backbone I performed the redirect using this code in routes.php (equivalent to routes.rb in Rails):

// Redirect /password-reset/XYZ to #/password-reset/XYZ
Route::get('/password-reset/{any}', function() {
    $url = Request::url();         // Get full URL
    $path = Request::path();       // Get portion of URL after the domain name
    return Redirect::to(str_replace($path, "#", $url) . $path);
});
like image 170
kevincolten Avatar answered Dec 08 '22 08:12

kevincolten