Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem integrating ahoy_email with mailkick #61

Closed
mwkling opened this issue May 10, 2016 · 3 comments
Closed

Problem integrating ahoy_email with mailkick #61

mwkling opened this issue May 10, 2016 · 3 comments

Comments

@mwkling
Copy link

mwkling commented May 10, 2016

Hello, I'm trying to integrate ahoy_email with mailkick and running into a SystemStackError: stack level too deep error.

My mailer code is simple:

class AdminMailer < ApplicationMailer
  # ...
  def generated_recommendations(recommendations)                                               
    @recommendations = recommendations
    mail(subject: "Recommendations generated for #{Date.today.strftime("%Y-%m-%d")}")      
  end 
end

Before it crashes, the stack trace looks like this:

--> #0  Mailkick::Mailer.mail(headers#Hash, &block#NilClass)
      at /home/mike/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/mailkick-0.1.4/lib/mailkick/mailer.rb:4
    #1  AhoyEmail::Mailer.mail_with_ahoy(headers#Hash, &block#NilClass)
      at /home/mike/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ahoy_email-0.3.0/lib/ahoy_email/mailer.rb:27
    #2  Mailkick::Mailer.mail(headers#Hash, &block#NilClass)
      at /home/mike/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/mailkick-0.1.4/lib/mailkick/mailer.rb:4
    #3  AhoyEmail::Mailer.mail_with_ahoy(headers#Hash, &block#NilClass)
      at /home/mike/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ahoy_email-0.3.0/lib/ahoy_email/mailer.rb:27
    #4  Mailkick::Mailer.mail(headers#Hash, &block#NilClass)
      at /home/mike/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/mailkick-0.1.4/lib/mailkick/mailer.rb:4

...

It looks like each gem calls the mail method in the other (or mail_with_ahoy in this case). I traced through it with byebug and the relevant Mailkick code is (see line with ***)

module Mailkick                                                                                
  module Mailer                                                                                
    def mail(headers = {}, &block)                                                             
      message = super  # *** This ends up calling AhoyEmail::Mailer.mail_with_ahoy

      Mailkick::Processor.new(message).process

      message
    end
  end
end

and the relevant AhoyEmail code is (see ***)

module AhoyEmail                                                                               
  module Mailer
    def self.included(base)
      base.extend ClassMethods                                                                 
      base.class_eval do
        # ...
        alias_method_chain :mail, :ahoy                                                        
      end                                                                                      
    end                                                                                        

    module ClassMethods                                                                        
    # ...
    def mail_with_ahoy(headers = {}, &block)
      # this mimics what original method does                                                  
      return message if @_mail_was_called && headers.blank? && !block

      message = mail_without_ahoy(headers, &block)  # *** This calls Mailkick::Mailer.mail
      AhoyEmail::Processor.new(message, self).process                                          
      message
    end     
  end     
end

Has anyone run into this problem before? To me it looks like the gems conflict and I don't see an obvious workaround. I was surprised since Mailkick is referenced in the Readme, so I was thinking I may be missing something obvious.

@edwinwills
Copy link

It looks like the version of ahoy_email on RubyGems isn't the most up-to-date - if you point your Gemfile at GitHub the issue should be fixed:

gem 'ahoy_email', github: 'ankane/ahoy_email'

@mwkling
Copy link
Author

mwkling commented May 12, 2016

Woohoo, that makes my life easy. I'm new enough to rails that I didn't think to check that but definitely something I'll keep in mind. Thanks!

@mwkling mwkling closed this as completed May 12, 2016
@ankane
Copy link
Owner

ankane commented May 12, 2016

Thanks for getting to the bottom of this. Just pushed a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants