Created
February 19, 2016 16:36
-
-
Save pedrovanzella/7d0988090a54bf052304 to your computer and use it in GitHub Desktop.
This file contains 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 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