Saving the information emailed and processed via Mailgun into my app

旧街凉风 提交于 2019-12-21 20:57:48

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/9644546/saving-the-information-emailed-and-processed-via-mailgun-into-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!