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

Doesn't work with any field #3

Open
Looooong opened this issue Dec 21, 2016 · 8 comments
Open

Doesn't work with any field #3

Looooong opened this issue Dec 21, 2016 · 8 comments

Comments

@Looooong
Copy link

Looooong commented Dec 21, 2016

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

@cainlevy
Copy link
Contributor

cainlevy commented Jan 9, 2017

@Looooong would you clarify how to reproduce this error?

@Looooong
Copy link
Author

Looooong commented Jan 10, 2017

@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?

@cainlevy
Copy link
Contributor

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]

@Looooong
Copy link
Author

Looooong commented Jan 13, 2017

Rails 4.2.6, ActionMailer 4.2.6, Mail 2.6.4

And source_location shows as you said.

@Looooong
Copy link
Author

Looooong commented Jan 13, 2017

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?'

@cainlevy
Copy link
Contributor

cainlevy commented Jan 13, 2017

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")

@Looooong
Copy link
Author

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

@Haegin
Copy link

Haegin commented Feb 11, 2020

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"

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