Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging mail delivery in IronWorker

Tags:

ruby

iron.io

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?

like image 405
Eric Andres Avatar asked May 15 '26 07:05

Eric Andres


1 Answers

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)

like image 129
user1951117 Avatar answered May 16 '26 22:05

user1951117



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!