3

I'm trying to use the mail gem to send an email from an IronWorker task. Running the script works on my local system (OS X), but fails when run on IronWorker with the same parameters. I'm new to IronWorker and the mail gem, so I'm at a loss of where to start debugging. Here's the text of the error message.

/task/email.rb:5:in `block in <top (required)>': undefined method `[]' for nil:NilClass (NoMethodError)     
from /task/__gems__/gems/mail-2.4.4/lib/mail/mail.rb:106:in `instance_eval'     
from /task/__gems__/gems/mail-2.4.4/lib/mail/mail.rb:106:in `defaults'  
from /task/email.rb:3:in `<top (required)>'     
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'  
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'  
from __runner__.rb:213:in `<main>'

And here's my code:

require 'mail'

Mail.defaults do
  delivery_method :smtp, {
    address: params['address'],
    port: 587,
    domain: params['domain'],
    user_name: params['username'],
    password: params['password'],
    authentication: 'plain',
    enable_starttls_auto: true
  }
end

Mail.deliver do
  to "#{params['to_name']} <#{params['to_address']}>"
  from "#{params['from_name']} <#{params['from_address']}>"
  subject "Mail test"
  text_part do
    body params['text']
  end
  html_part do
    content_type 'text/html; charset=UTF-8'
    body params['html']
  end
end

Note that I was getting this error before locally, but it was caused by using username in the defaults instead of user_name. Any ideas?

Eric Andres
  • 3,417
  • 2
  • 24
  • 40
  • Hey Eric - it would help to share the code where you are constructing the parameters and then queuing your worker up as well. Seems that params is nil as mentioned below. – Chad Jul 12 '13 at 17:38
  • Params isn't nil. I had a logging statement in before, and I could pull out all of my parameters. It's something in the `defaults` method of Mail. I don't have any code constructing the parameters yet. I'm just doing `iron_worker queue email -p {...}` on the command line. I'll post my json later if it helps. – Eric Andres Jul 12 '13 at 19:45
  • @EricAndres were you able to fix this? The output of your params would help. – Travis Reeder Jul 19 '13 at 19:13

1 Answers1

1

I'm not sure but looks like 'params' is nil, could you try to inspect it before using in. It could happened if you're using in your worker separate namespaces (like worker body inside class)