Class: MailSpy::SendgridController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mail_spy/sendgrid_controller.rb

Instance Method Summary collapse

Instance Method Details

#notificationObject

Parses a notification from the sendgrid system



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/mail_spy/sendgrid_controller.rb', line 5

def notification
  #Must be passed in via SendGrids SMTP API Headers
  email_id = params['eid']
  return head 400 if email_id.blank? || params[:event].blank?

  #Send grid event name
  event_action = "sendgrid-#{params[:event]}"

  case params[:event]
    when 'bounce', 'dropped'
      MailSpy.track_action(email_id, event_action, {:reason => params[:reason]})
    when 'click'
      MailSpy.track_action(email_id, event_action, {:url => params[:url]})
    when 'deferred', 'delivered', 'processed', 'open', 'spamreport', 'unsubscribe'
      MailSpy.track_action(email_id, event_action)
  end

  head :ok
end