简体   繁体   English

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

[英]How to get email reply on rails app from email server

I need to implement messaging feature. 我需要实现消息传递功能。 When I send message to any user from my rails app then it also goes to users email. 当我从rails应用程序向任何用户发送消息时,它也会转到用户的电子邮件。 But what I need to implement if user who got the email make reply from gmail,yahoo..etc then the reply should also come into rails app. 但是,如果收到电子邮件的用户通过gmail,yahoo..etc做出回复,我需要实现的,那么回复也应该进入rails应用程序。 could anyone guide me some way.. so I can search it on google. 任何人都可以指导我..所以我可以在谷歌搜索它。

For Example: 例如:

If I send email to user from this email "mc-6bckm434ls@reply.xyz.com" and user replied on gspq5diedss@reply.xyz.com which I set Reply-To in header. 如果我通过电子邮件“mc-6bckm434ls@reply.xyz.com”向用户发送电子邮件,用户在gspq5diedss@reply.xyz.com上Reply-To ,我在标题中设置了Reply-To Then I need user's reply in my rails application so that I can add this user's reply into my messaging thread. 然后我需要用户在rails应用程序中的回复,以便我可以将此用户的回复添加到我的消息传递线程中。 By this feature which I want to implement User do not need to login in my application to do message, user can do message on current conversation via email reply also. 通过我想实现的这个功能用户不需要在我的应用程序中登录做消息,用户也可以通过电子邮件回复在当前对话上做消息。

Since you tagged the question SendGrid, I'm assuming you're using it. 既然你标记了问题SendGrid,我假设你正在使用它。 You can use SendGrid's Inbound Parse Webhook to handle parsing incoming messages. 您可以使用SendGrid的Inbound Parse Webhook来处理解析传入的消息。

We also have a recent tutorial that goes through using the webhook in a rails app: http://sendgrid.com/blog/two-hacking-santas-present-rails-the-inbound-parse-webhook/ 我们还有一个最近的教程,通过在rails应用程序中使用webhook: http//sendgrid.com/blog/two-hacking-santas-present-rails-the-inbound-parse-webhook/

It's possible ! 这是可能的 !

You can use mailman for example. 例如,您可以使用mailman

All you have to do is set a Reply-To header in your e-mail to make it unique, so when you fetch messages you know to what it corresponds. 您所要做的就是在电子邮件中设置一个Reply-To标题以使其唯一,因此当您获取消息时,您知道它对应的内容。

For example, let's say you own the e-mail address foo@bar.com 例如,假设您拥有电子邮件地址foo@bar.com

You could send e-mails with a reply-to header "foo+content_id@bar.com", so you know what the user is replying to. 您可以发送带有回复标题“foo+content_id@bar.com”的电子邮件,以便您知道用户回复的内容。

Then, mailman can fetch the messages from the mailbox and parse the content id in them. 然后,mailman可以从邮箱中获取邮件并解析其中的内容ID。

Some services do that as well, handling all the emailing part and sending you notifications for incoming e-mails, for example, postmark 有些服务也会这样做,处理所有电子邮件部分并向您发送传入电子邮件的通知,例如邮戳

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

There is a railscast about using the gem but its pay-only :-/ http://railscasts.com/episodes/313-receiving-email-with-mailman , 有一个关于使用宝石的轨道广播,但只付费: - / http://railscasts.com/episodes/313-receiving-email-with-mailman

however, there is the github repo from the railscast which can showcase you an example app that uses mailman (with before & after so you can track the changes) - https://github.com/railscasts/313-receiving-email-with-mailman 然而,有来自railscast的github repo可以向你展示一个使用mailman的示例应用程序(之前和之后可以跟踪更改) - https://github.com/railscasts/313-receiving-email-with -mailman

Ruby on Rails introduced Action Mailbox in version 6.0 Ruby on Rails在6.0版中引入了Action Mailbox

With ActionMailbox you can easily configure rules where to route incoming emails (examples from the documentation): 使用ActionMailbox,您可以轻松配置路由传入电子邮件的规则(文档中的示例):

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

And how to handle specific messages in a mailbox: 以及如何处理邮箱中的特定邮件:

# 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

Find the documentation about how to configure Action Mailbox and some examples in the Rails Guides . 查找有关如何配置Action Mailbox的文档以及Rails指南中的一些示例。

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

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