Reputation: 753
I have set up a staging instance of a rails 3.1 application on Heroku and everything seems to work fine except I'm getting a strange error when I try to send emails. I am using the sendgrid starter addon for email delivery. The full error is below:
NoMethodError: undefined method `index' for #<Mail::Message:0x000000048daf28>
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:1289:in `method_missing'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:117:in `value_decode'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:101:in `decode_encode'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/fields/unstructured_field.rb:74:in `do_decode'
if I just generate the message object without calling deliver on it and inspect it everything seems fine. I am not seeing this error on my production app. Can you tell me what this error means and how to resolve it? Thanks.
Upvotes: 4
Views: 2623
Reputation: 2200
I had a similar problem. However, the error I received was:
NoMethodError (undefined method `ascii_only?' for nil:NilClass)
My problem was I had:
mail(to: emails,....)
And my variable "emails" was actually an array, instead of being one single string of emails.
Upvotes: 0
Reputation: 842
This error happened because I was setting custom headers to an integer value. Using to_s on these values resolved the issue for me.
Upvotes: 0
Reputation: 753
This error was the result of using Class instead of Module when defining a mail helper I'd created.
Upvotes: 1
Reputation: 12397
Got the same error on my local machine using Rails 3.0.11. It happened after I passed some object instead of a string to the mail
:to
attribute. So be sure that the :to
attribute is a string!
mail(to: object.to_s)
Upvotes: 11
Reputation: 107728
A new version of Mail, Mail 2.4.0, was released this weekend. I would recommend upgrading to this latest version and seeing if that has fixed your issue.
Upvotes: 1