Sha256: 4f4ccca3369d0441b16b900a557e36f670f746ab4c576a22bd5cff67c0bd77a6
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
# class EmailResponsesController < ApplicationController # end require 'json' require 'aws-sdk' class EmailResponsesController < ApplicationController # skip_authorization_check # skip_before_action :verify_authenticity_token before_action :log_incoming_message def bounce # return render json: {} unless aws_message.authentic? if type != 'Bounce' Rails.logger.info "Not a bounce - exiting" return render json: {} end bounce = message['bounce'] bouncerecps = bounce['bouncedRecipients'] bouncerecps.each do |recp| email = recp['emailAddress'] extra_info = "status: #{recp['status']}, action: #{recp['action']}, diagnosticCode: #{recp['diagnosticCode']}" Rails.logger.info "Creating a bounce record for #{email}" EmailResponse.create ({ email: email, response_type: 'bounce', extra_info: extra_info}) end render json: {} end def complaint # return render json: {} unless aws_message.authentic? if type != 'Complaint' Rails.logger.info "Not a complaint - exiting" return render json: {} end complaint = message['complaint'] recipients = complaint['complainedRecipients'] recipients.each do |recp| email = recp['emailAddress'] extra_info = "complaintFeedbackType: #{complaint['complaintFeedbackType']}" EmailResponse.create ( { email: email, response_type: 'complaint', extra_info: extra_info } ) end render json: {} end protected def aws_message # @aws_message ||= AWS::SNS::Message.new request.raw_post end def log_incoming_message print "----------" Rails.logger.info request.raw_post end # Weirdly, AWS double encodes the JSON. def message @message ||= JSON.parse JSON.parse(request.raw_post)['Message'] end def type message['notificationType'] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aws_email_bounce-0.1.1 | app/controllers/email_responses_controller.rb |