Griddler gem throwing exception while parsing an incoming email

450 views Asked by At

I have integrated Sendgrid incoming parse Webhook API, and it is correctly posting the email object to my rails app. On app I'm using griddler gem to catch and do further processing of email data. But I'm getting following exception:

Sent mail to [email protected] (77.6ms)
F, [2014-11-14T17:48:05.851336 #24799] FATAL -- :
NoMethodError (undefined method `process' for #<EmailProcessor:0x0000000a2ad5f0>):
  griddler (1.1.0) app/controllers/griddler/emails_controller.rb:19:in `public_send'
  griddler (1.1.0) app/controllers/griddler/emails_controller.rb:19:in `process_email'
  griddler (1.1.0) app/controllers/griddler/emails_controller.rb:4:in `block in create'
  griddler (1.1.0) app/controllers/griddler/emails_controller.rb:3:in `each'
  griddler (1.1.0) app/controllers/griddler/emails_controller.rb:3:in `create'
  actionpack (4.1.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.4) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'

Where as I have the process instance method in /mailer/email_processor.rb

class EmailProcessor
  def initialize(email)
    @email = email
    puts "initialized Email Processor\n\n\n\n\n\n\n\n" # Should see this line in log
  end

  def process
    user = User.find_by_email(@email.from[:email])
    puts @email.inspect and return if user.blank?

    puts "############### @email = #{@email.inspect}###############\n\n\n\n\n\n\n"
  end
end

Here is config/initializer/griddler.rb

Griddler.configure do |config|
  config.processor_class = EmailProcessor
  config.processor_method = :process
  config.reply_delimiter = '-- REPLY ABOVE THIS LINE --'
  config.email_service = :sendgrid
end

Here is the version of gem I'm using:

#Process incoming mail from sendgrid smtp server
gem 'griddler', "~> 1.1.0"
gem 'griddler-sendgrid', "~> 0.0.1"

This is based on documentation available on griddler github

Can anyone please help me with what I'm missing here. Also, why I don't see following line in log ?

"initialized Email Processor\n\n\n\n\n\n\n\n"

Following is the line to define route

mount_griddler

EDIT: As far as I know, rails doesn't add any such class directly. Strangely I'm able to see the 'process' method available for 'EmailProcessor' class in 'rails console':

2.1.4 :005 > x = EmailProcessor.new(1)
initialized Email Processor\n\n\n\n\n\n\n\n
 => #<EmailProcessor:0x007fc6ae5aee08 @email=1>
2.1.4 :006 > x.methods
 => [:process, :blank?, :present?, ...
2.1.4 :014 > EmailProcessor.instance_methods(false)
 => [:process]

Thanks

1

There are 1 answers

0
Indyarocks On BEST ANSWER

The issue was, the EmailProcessor class was not being loaded with rails application startup. Adding following lines to application.rb did the magic:

 config.autoload_paths += %W(#{config.root}/app/mailers/email_processor.rb)

NOTE: You'll need to restart your server, every time you make changes to email_processor.rb.

Thanks to Joel Oliveira (Author of Griddler) to responding to my personal email and pointing out the issue :)