简体   繁体   English

有任何简单的方法可以使用Rails ActionMailer将电子邮件分组到一个线程中吗?

[英]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. 我希望在某些情况下(例如来自GitHub的电子邮件)将从我的Rails应用发送给用户的电子邮件分组为线程。 (in Gmail and Outlook.) (在Gmail和Outlook中。)

在此处输入图片说明

I know that needs the emails having specific Message-IDs in In-Reply-To or References email headers. 我知道这需要在In-Reply-ToReferences电子邮件标头中具有特定Message-ID的电子邮件。

Do I have to manage all the Message-IDs in the database? 我是否需要管理数据库中的所有Message-ID? Or is there smarter ways to to that in Ruby on Rails? 还是在Ruby on Rails中有更聪明的方法来做到这一点?

I want to know the best practice to threadify emails in Rails. 我想知道在Rails中对电子邮件进行线程化的最佳实践。

There is no need to keep track of the Message-ID in the database. 无需跟踪数据库中的Message-ID。

The only thing you need is a method that generates the same Message-ID for the same input (for example an md5 hash ). 您唯一需要的是为相同输入生成相同Message-ID的方法(例如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. 在您的示例中,来自GitHub的有关特定拉取请求的分组电子邮件,他们本可以使用id作为输入。

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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