Question

I have set up Heroku & Railgun in order to be able to take the content from emails and store it.

I've got it to the point that when emails are sent to mailgun, they are forwarded to my app and empty instaces of my messages model are created automatically, however, none of the fields from the email are being stored (despite having a matched schema (eg. from:string subject:string etc)).

My issue is that I can't figure out how to take the contents of a HTTP POST request and process it so that each message is stored with its corresponding information. I can see that it is coming into heroku (via heroku logs), but cannot store it. I'm looking to store at first the following fields:

  • From
  • Subject
  • Attachments

At the moment my messages_controller.rb looks like this

    def create
      @message = Message.new(params[:message])

      respond_to do |format|
        if @message.save
          format.html { redirect_to @message, notice: 'Message was successfully created.' }
          format.json { render json: @message, status: :created, location: @message }
        else
          format.html { render action: "new" }
          format.json { render json: @message.errors, status: :unprocessable_entity }
        end
      end
    end

Any suggestions?

I'm sure its a basic comprehension problem on my part, but I can't seem to find anything that really explains what I'm trying to do here.

Was it helpful?

Solution

The mailgunner here:

We do not post Rails objects, we post simple HTTP parameters as explained in this table: http://documentation.mailgun.net/user_manual.html#parsed-messages-parameters

There is no "message" parameter which you're trying to grab with params[:message], you should assemble your message with individual components like parmas[:Subject], params[:body-plain], etc.

Also, since the POST is coming from a different domain, you need to disable Rails request forgery protection for this controller action: http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html

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