简体   繁体   中英

Any easy ways to group the emails together into a thread using Rails ActionMailer?

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM