Ruby on rails 如何在rails应用程序上从电子邮件服务器获取电子邮件回复
我需要实现消息传递功能。当我从rails应用程序向任何用户发送消息时,它也会发送给用户电子邮件。但我需要实现的是,如果收到电子邮件的用户从gmail、yahoo等处回复,那么回复也应该进入rails应用程序。谁能给我指点路吗。。所以我可以在谷歌上搜索 例如: 如果我通过此电子邮件“mc”向用户发送电子邮件-6bckm434ls@reply.xyz.com”用户回答说gspq5diedss@reply.xyz.com我在标题中设置了回复。然后,我需要rails应用程序中的用户回复,以便我可以将该用户的回复添加到我的消息传递线程中。 通过这个我想实现的功能,用户不需要登录我的应用程序来发送消息,用户也可以通过电子邮件回复当前对话中的消息。这是可能的 例如,您可以使用 您所要做的就是在电子邮件中设置一个Ruby on rails 如何在rails应用程序上从电子邮件服务器获取电子邮件回复,ruby-on-rails,email,sendgrid,Ruby On Rails,Email,Sendgrid,我需要实现消息传递功能。当我从rails应用程序向任何用户发送消息时,它也会发送给用户电子邮件。但我需要实现的是,如果收到电子邮件的用户从gmail、yahoo等处回复,那么回复也应该进入rails应用程序。谁能给我指点路吗。。所以我可以在谷歌上搜索 例如: 如果我通过此电子邮件“mc”向用户发送电子邮件-6bckm434ls@reply.xyz.com”用户回答说gspq5diedss@reply.xyz.com我在标题中设置了回复。然后,我需要rails应用程序中的用户回复,以便我可以将该用
回复
标题,使其具有唯一性,这样当您获取消息时,您就知道它对应的内容
例如,假设您拥有该电子邮件地址foo@bar.com
您可以发送回复标题为“foo+内容”的电子邮件_id@bar.com,这样您就知道用户正在回复什么
然后,邮递员可以从邮箱中提取邮件并解析其中的内容id
有些服务也会这样做,处理所有的电子邮件部分,并向您发送接收电子邮件的通知,例如,请参阅
有一个关于使用gem的railscast,但它的报酬仅为:-/
然而,railscast上的github repo可以向您展示一个使用mailman的示例应用程序(带有before&after,以便您可以跟踪更改)既然您标记了问题SendGrid,我假设您正在使用它。您可以使用SendGrid来处理对传入消息的解析 我们还有一个在rails应用程序中使用webhook的最新教程:6.0版中引入的RubyonRails 使用ActionMailbox,您可以轻松配置路由传入电子邮件的规则(文档中的示例):
#app/mailboxs/application_mailbox.rb
类ApplicationMailbox:转发
路由/@回复\./i=>:回复
结束
以及如何处理邮箱中的特定邮件:
# app/mailboxes/forwards_mailbox.rb
class ForwardsMailbox < ApplicationMailbox
# Callbacks specify prerequisites to processing
before_processing :require_forward
def process
if forwarder.buckets.one?
record_forward
else
stage_forward_and_request_more_details
end
end
private
def require_forward
unless message.forward?
# Use Action Mailers to bounce incoming emails back to sender – this halts processing
bounce_with Forwards::BounceMailer.missing_forward(
inbound_email, forwarder: forwarder
)
end
end
def forwarder
@forwarder ||= Person.where(email_address: mail.from)
end
def record_forward
forwarder.buckets.first.record \
Forward.new forwarder: forwarder, subject: message.subject, content: mail.content
end
def stage_forward_and_request_more_details
Forwards::RoutingMailer.choose_project(mail).deliver_now
end
end
#app/mailboxs/forwards_mailbox.rb
类转发邮箱
在中查找有关如何配置操作邮箱的文档和一些示例。我很想知道的是,可能必须创建一个gmail帐户,并让rails轮询该帐户以接收电子邮件。这是最简单的解决办法。谷歌“ruby gmail”搜索一些你可以使用的宝石。
# app/mailboxes/forwards_mailbox.rb
class ForwardsMailbox < ApplicationMailbox
# Callbacks specify prerequisites to processing
before_processing :require_forward
def process
if forwarder.buckets.one?
record_forward
else
stage_forward_and_request_more_details
end
end
private
def require_forward
unless message.forward?
# Use Action Mailers to bounce incoming emails back to sender – this halts processing
bounce_with Forwards::BounceMailer.missing_forward(
inbound_email, forwarder: forwarder
)
end
end
def forwarder
@forwarder ||= Person.where(email_address: mail.from)
end
def record_forward
forwarder.buckets.first.record \
Forward.new forwarder: forwarder, subject: message.subject, content: mail.content
end
def stage_forward_and_request_more_details
Forwards::RoutingMailer.choose_project(mail).deliver_now
end
end