Skip to content

Instantly share code, notes, and snippets.

@pedrovanzella
Created February 19, 2016 16:36
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 pedrovanzella/7d0988090a54bf052304 to your computer and use it in GitHub Desktop.
Save pedrovanzella/7d0988090a54bf052304 to your computer and use it in GitHub Desktop.
class MailController < ApplicationController
def send(e)
begin
UserMailer.email(required_params[:to],
required_params[:from],
required_params[:template],
required_params[:content])
.deliver_now
rescue Exceptions::InvalidTemplateError
render json: {success: false,
reason: 'bad-template'}
rescue Exceptions::InvalidEmailFormat
render json: {success: false,
reason: 'bad-to-email'}
rescue Exceptions::InvalidFromEmail
render json: {success: false,
reason: 'bad-from-email'}
rescue Exceptions::InvalidContent
render json: {success: false,
reason: 'bad-content'}
end
render json: {success: true}
end
def required_params
params.require(:to)
.require(:from)
.require(:template)
.require(:content)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment