Created
January 24, 2013 22:25
-
-
Save rlmattax/4628713 to your computer and use it in GitHub Desktop.
Sendgrid Listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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