Last active
December 13, 2015 23:38
-
-
Save starrhorne/4992632 to your computer and use it in GitHub Desktop.
Example Incoming Email Receiver for a Rails Application
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
# 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 |
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
# 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 |
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
# 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