app/controllers/msg/bounces_controller.rb
# When the subscription is first set up they will also POST us a SubscriptionConfirmation,
# upon which we have to GET the given url to confirm that we are able to follow orders.
#
When the subscription is first set up they will also POST us a SubscriptionConfirmation,
upon which we have to GET the given url to confirm that we are able to follow orders.
When the subscription is first set up they will also POST us a SubscriptionConfirmation upon which we have to GET the given url to confirm that we are able to follow orders .
def create
      if request.env['x-amz-sns-message-type'] == 'SubscriptionConfirmation' || ENV['HTTP_X_AMZ_SNS_MESSAGE_TYPE'] == "SubscriptionConfirmation" || @data['Type'] == "SubscriptionConfirmation"
        response = HTTParty.get(@data['SubscribeURL'])
        head :ok
      else
        mail_data = @data['mail']
        bounce_data = @data['bounce']
        recipients = [bounce_data['bouncedRecipients']].flatten
        envelope = Msg::Envelope.find_by_email_id(mail_data['messageId'])
        recipients.each do |recipient_data|
          Msg::Bounce.create({
            :envelope => envelope,
            :bounce_type => bounce_data['bounceType'],
            :bounce_subtype => bounce_data['bounceSubType'],
            :reporter => bounce_data['reportingMTA'],
            :email => recipient_data['emailAddress'],
            :status => recipient_data['status'],
            :diagnostic => recipient_data['diagnosticCode'],
            :raw_message => JSON.dump(bounce_data)
          })
        end
        head :ok
      end
    end
def create if request . env [ 'x-amz-sns-message-type' ] == 'SubscriptionConfirmation' || ENV [ 'HTTP_X_AMZ_SNS_MESSAGE_TYPE' ] == "SubscriptionConfirmation" || @data [ 'Type' ] == "SubscriptionConfirmation" response = HTTParty . get ( @data [ 'SubscribeURL' ] ) head :ok else mail_data = @data [ 'mail' ] bounce_data = @data [ 'bounce' ] recipients = [ bounce_data [ 'bouncedRecipients' ] ] . flatten envelope = Msg :: Envelope . find_by_email_id ( mail_data [ 'messageId' ] ) recipients . each do | recipient_data | Msg :: Bounce . create ( { :envelope => envelope , :bounce_type => bounce_data [ 'bounceType' ] , :bounce_subtype => bounce_data [ 'bounceSubType' ] , :reporter => bounce_data [ 'reportingMTA' ] , :email => recipient_data [ 'emailAddress' ] , :status => recipient_data [ 'status' ] , :diagnostic => recipient_data [ 'diagnosticCode' ] , :raw_message => JSON . dump ( bounce_data ) } ) end head :ok end end
When the subscription is first set up they will also POST us a SubscriptionConfirmation,
upon which we have to GET the given url to confirm that we are able to follow orders.
When the subscription is first set up they will also POST us a SubscriptionConfirmation upon which we have to GET the given url to confirm that we are able to follow orders .