Question

I need to implement messaging feature. When I send message to any user from my rails app then it also goes to users email. 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. 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. Then I need user's reply in my rails application so that I can add this user's reply into my messaging thread. 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.

Was it helpful?

Solution

Since you tagged the question SendGrid, I'm assuming you're using it. You can use SendGrid's Inbound Parse Webhook to handle parsing incoming messages.

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/

OTHER TIPS

It's possible !

You can use mailman for example.

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.

For example, let's say you own the e-mail address 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.

Then, mailman can fetch the messages from the mailbox and parse the content id in them.

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

There is a railscast about using the gem but its pay-only :-/ 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

Ruby on Rails introduced Action Mailbox in version 6.0

With ActionMailbox you can easily configure rules where to route incoming emails (examples from the documentation):

# 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top