Skip to content

Instantly share code, notes, and snippets.

@starrhorne
Last active December 13, 2015 23:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starrhorne/4992632 to your computer and use it in GitHub Desktop.
Save starrhorne/4992632 to your computer and use it in GitHub Desktop.
Example Incoming Email Receiver for a Rails Application
# app/controllers/emails_controller.rb
class EmailsController < ActionController::Base
def create
if EmailToSmsReceiver.receive(request)
render :json => { :status => 'ok' }
else
render :json => { :status => 'rejected' }, :status => 403
end
end
end
# app/email_receivers/incoming.rb
class EmailToSmsReceiver < Incoming::Strategies::Postmark
def receive(mail)
send_sms([mail.subject, mail.body].join(": "))
end
private
def send_sms(message)
# Insert twilio magic here
end
end
# config/routes.rb
Rails.application.routes.draw do
post '/emails' => 'emails#create'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment