Reputation: 2587
I want the emails sent from my Rails app to the users to be grouped into threads in some conditions, like the emails from GitHub do. (in Gmail and Outlook.)
I know that needs the emails having specific Message-IDs in In-Reply-To
or References
email headers.
Do I have to manage all the Message-IDs in the database? Or is there smarter ways to to that in Ruby on Rails?
I want to know the best practice to threadify emails in Rails.
Upvotes: 0
Views: 336
Reputation: 106922
There is no need to keep track of the Message-ID in the database.
The only thing you need is a method that generates the same Message-ID for the same input (for example an md5 hash
). And the input of that method must be something that does not change and identifies all messages that should be grouped together. In your example with the grouped emails from GitHub about specific pull requests, they could have used the id as an input.
I would start to play around with something like this:
require 'digets'
def message_id(identifer)
Digest::MD5.hexdigest(identifer)
end
message_id("pull-123")
#=> "23172d2caceae88a1152e967af71fc6e"
message_id("issue-456")
#=> "26c89ed68512269d003d32811bbd4527"
Upvotes: 2