Skip to content

Instantly share code, notes, and snippets.

@rlmattax
Created January 24, 2013 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlmattax/4628713 to your computer and use it in GitHub Desktop.
Save rlmattax/4628713 to your computer and use it in GitHub Desktop.
Sendgrid Listener
class ListenerController < ApplicationController
skip_before_filter :verify_authenticity_token
def receive_email
@params = params
@inbound_email = InboundEmail.new(:text => params["text"],
:html => params["html"],
:to => clean_field(params["to"]),
:from => clean_field(params["from"]),
:subject => clean_field(params["subject"])
)
respond_to do |format|
if @inbound_email.save && request.post?
@inbound_email.process_incoming_email
flash[:notice] = 'Item was succesffully created.'
format.xml {render :xml => @inbound_email, :status => :created }
else
flash[:notice] = "Ooops, we had an error saving that item."
format.xml {render :xml => @inbound_email.errors, :status => :unprocessable_entity }
end
end
end
private
def clean_field(input_string)
input_string.gsub(/\n/,'') if input_string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment