如何从电子邮件服务器上获取有关rails app的电子邮件回复

时间:2014-01-09 09:44:06

标签: ruby-on-rails email sendgrid

我需要实现消息传递功能。当我从rails应用程序向任何用户发送消息时,它也会转到用户的电子邮件。但是,如果收到电子邮件的用户通过gmail,yahoo..etc做出回复,我需要实现的,那么回复也应该进入rails应用程序。任何人都可以指导我..所以我可以在谷歌上搜索。

例如:

如果我通过此电子邮件“mc-6bckm434ls@reply.xyz.com”向用户发送电子邮件,并且用户在gspq5diedss@reply.xyz.com上回复,我在标题中设置了Reply-To。然后我需要用户在rails应用程序中的回复,以便我可以将此用户的回复添加到我的消息传递线程中。 通过我想要实现的这个功能用户不需要在我的应用程序中登录做消息,用户也可以通过电子邮件回复在当前对话上做消息。

4 个答案:

答案 0 :(得分:7)

由于您标记了问题SendGrid,我假设您正在使用它。您可以使用SendGrid的Inbound Parse Webhook来处理解析传入的消息。

我们还有一个最近的教程,在rails应用程序中使用webhook:http://sendgrid.com/blog/two-hacking-santas-present-rails-the-inbound-parse-webhook/

答案 1 :(得分:1)

这是可能的!

例如,您可以使用mailman

您所要做的就是在电子邮件中设置Reply-To标题以使其唯一,因此当您获取消息时,您知道它对应的内容。

例如,假设您拥有电子邮件地址foo@bar.com

您可以发送带有回复标题“foo+content_id@bar.com”的电子邮件,以便您知道用户回复的内容。

然后,mailman可以从邮箱中获取邮件并解析其中的内容ID。

某些服务也会这样做,处理所有电子邮件部分并向您发送传入电子邮件的通知,例如postmark

答案 2 :(得分:0)

请参阅https://github.com/titanous/mailman/blob/master/USER_GUIDE.md

有一个关于使用宝石的轨道广播,但只付费: - / http://railscasts.com/episodes/313-receiving-email-with-mailman

然而,有一个来自railscast的github repo可以向你展示一个使用mailman的示例应用程序(在之前和之后可以跟踪更改) - https://github.com/railscasts/313-receiving-email-with-mailman

答案 3 :(得分:0)

Ruby on Rails在版本6.0中引入了Action Mailbox

使用ActionMailbox,您可以轻松配置将传入电子邮件路由到哪里的规则(来自文档的示例):

# app/mailboxes/application_mailbox.rb
class ApplicationMailbox < ActionMailbox::Base
  routing /^save@/i     => :forwards
  routing /@replies\./i => :replies
end

以及如何处理邮箱中的特定邮件:

# 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

Rails Guides中找到有关如何配置操作邮箱的文档和一些示例。

相关问题