mail-x_smtpapi icon indicating copy to clipboard operation
mail-x_smtpapi copied to clipboard

Doesn't work with any field

Open Looooong opened this issue 8 years ago • 8 comments

NoMethodError: undefined method `values' for "{\"category\": \"Category\"}":String
from /var/lib/gems/2.3.0/gems/mail-x_smtpapi-1.1.0/lib/mail_x_smtpapi/field.rb:40:in `empty?'

Rails version 4.2.6

Looooong avatar Dec 21 '16 10:12 Looooong

@Looooong would you clarify how to reproduce this error?

cainlevy avatar Jan 09 '17 21:01 cainlevy

@cainlevy I just try a piece of example code in my project code

mail.smtpapi.category = 'Category'

It seems like the Field#empty? expect each of value.values to be Hash, but it turns out to be String. I tried with field category, filters, unique_args, and all of them raise the same execption.

Perhaps this error relates to the version of Rails?

Looooong avatar Jan 10 '17 09:01 Looooong

Perhaps this error relates to the version of Rails?

Sure, what versions of Rails and Mail do you have?

Would you also try:

mail.method(:smtpapi).source_location

Which should look something like:

".../mail-x_smtpapi/lib/mail/x_smtpapi.rb", 6]

cainlevy avatar Jan 10 '17 15:01 cainlevy

Rails 4.2.6, ActionMailer 4.2.6, Mail 2.6.4

And source_location shows as you said.

Looooong avatar Jan 13 '17 15:01 Looooong

class TestMailer < ActionMailer::Base
  def test
    mail.smtpapi.category = 'My category'
    mail(to: '[email protected]', subject: 'Test')
  end
end

[3] pry(main)> TestMailer.test.deliver_now
Rendered test_mailer/test.html.slim (43.4ms) Rendered test_mailer/test.html.slim (1.9ms)

TestMailer#test: processed outbound mail in 220.4ms

Sent mail to [email protected] (11.5ms) nil NoMethodError: undefined method 'values' for "{"category": "My category"}":String from /var/lib/gems/2.3.0/gems/mail-x_smtpapi-1.1.0/lib/mail_x_smtpapi/field.rb:40:in `empty?'

Looooong avatar Jan 13 '17 15:01 Looooong

this works for me:

require 'bundler/inline'

gemfile true do
  source 'https://rubygems.org'
  gem 'rails', '4.2.6'
  gem 'mail', '2.6.4'
  gem 'mail-x_smtpapi', path: './'
end

require 'action_mailer'

ActionMailer::Base.delivery_method = :test

class TestMailer < ActionMailer::Base
  def test
    mail(from: '[email protected]', to: '[email protected]', subject: 'Test', body: 'hello world')
    # had to move this line down so that actionmailer wouldn't complain about a missing template
    mail.smtpapi.category = 'My Category'
  end
end

TestMailer.test.deliver_now

So I wonder if you have a gem conflict. Your pasted pry session says that the mail is delivered and then errors. Maybe that's a Mail observer? I believe you can check with:

Mail.class_variable_get("@@delivery_notification_observers")

cainlevy avatar Jan 13 '17 16:01 cainlevy

[16] pry(main)> Mail.class_variable_get("@@delivery_notification_observers")
=> []

Looooong avatar Jan 14 '17 04:01 Looooong

I ran into the same error when I tried to pass the unsubscribe group ID as an integer instead of as a string. Hope this helps anyone making the same mistake I did.

Bad

message.smtpapi.asm_group_id = 52

Good

message.smtpapi.asm_group_id = "52"

Haegin avatar Feb 11 '20 21:02 Haegin