Google Mail Conversation Threading, and how to prevent

Tired of Google mail taking your e-mail and matching it to a gmail conversation incorrectly? Google mail has many cool features, one of which is the e-mail conversation thread view. This view shows e-mails matched based on subject, time, and correspondence grouped together to see a chronological conversation. While this is a neat feature that has made Gmail unique for so long, it can become cumbersome to companies and web developers as they try to ship out monthly statements, e-mail notices, or any other e-mail that for some reason has the same subject every time it is sent out.

The question I asked was: Is it sufficient to change the subject text every time I send out an e-mail?

The answer was no. The reason(s) were simple: the e-mail may need the same subject and/or you may not want to send your customer an e-mail with a unique character sequence in it that the user can see and potentially become confused about.

The solution: Follow suit with another cool feature Google mail has made apparent, the use of virtual inboxing. Add a short web-friendly unique code to your e-mail address username, appending with a + sign.

ephekt@gmail.com becomes ephekt+nM2eY@gmail.com

The key to this is that you should have a friendly name on your e-mail so that the recipient does not see the difference in e-mail addresses. Thus, with slight modification we now arrive at:

Mike R <ephekt@gmail.com> becomes Mike R <ephekt+nM2eY@gmail.com>

And to the end user all is sane. There are a few ways to generate unique tokens… In a Ruby on Rails project I used the built-in base 64 encoder, passing in a random number up to 3 characters long so that my generated code would not only be highly unique but relatively short.

def friendly_email_token
  ActiveSupport::Base64.encode64(rand(0x10000).to_s).tr("/+","_.").gsub(/=*\n/,"")
end

Just throw the above method into one of your classes and then you can define a method that appends this friendly_email_token to your e-mail address.

def randomize_address email
  unless email.blank?
    username, domain = email.split("@", 2)
    "#{username}+{friendly_email_token}@#{domain}"
  end
end

And voila! We’re good to go. Call the randomize_address method with your e-mail (with or without a friendly name) and it will do the work.

2 Comments

  1. I came up with this idea on my own to solve the problem of forms coming from our Web sites being grouped into threads incorrectly, however, the “From” header that I specify for the e-mail when connecting to Gmail SMTP gets overridden. So if the “From” address I specify is “forms+abc123@domain.com”, Gmail just ignores that and puts in “forms@domain.com.” (The same happens if you try to specify any other address when sending from forms@domain.com.)

    Perhaps my problem wouldn’t exist if we weren’t sending through Gmail as well as receiving through gmail….

  2. That’s odd. You pretty much described a similar behavior I was trying to compensate for. But I see what you’re saying, maybe because you sent from email+xxx@mydomain.com and receive at email@mydomain.com GMail tries to get smart and remove the filter in the e-mail. Have you tried sending to another GMail address (just for shits and giggles)? If you can share code that might help as well. Let’s solve this!!

Leave a Reply

Your email address will not be published. Required fields are marked *