我正在尝试使用mail
gem 从 IronWorker 任务中发送电子邮件。运行脚本可以在我的本地系统 (OS X) 上运行,但在 IronWorker 上使用相同参数运行时会失败。我是 IronWorker 和mail
gem 的新手,所以我不知道从哪里开始调试。这是错误消息的文本。
/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>'
这是我的代码:
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
请注意,我之前在本地收到此错误,但它是由username
在默认值中使用而不是user_name
. 有任何想法吗?