所以我在ruby中写了这个非常简单的emailer实用程序,但是当我运行它时它告诉我,我正在通过一个我不应该参与的论点?
1 #!/usr/bin/ruby
2 require 'mail'
3
4 class Mailer
5
6 #Sends emails without attachment
7 def send(subject,recipients,body,from)
8 Mail.defaults do
9 delivery_method :smtp,{ :address => 'localhost', :port => 25,:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE}
10 end
11 mail = Mail.new do
12 from "#{from}"
13 to "#{recipient}"
14 subject "#{subject}"
15 body "#{body}"
16 end
17 mail.deliver!
18 end
19
20 end
我这样运行:
subject="something"
recipients="me@mycompany.com"
mailer=Mailer.new
from="me@mycompany.com"
body="this is the body"
mailer=Mailer.new
mailer.send(subject,recipients,body,from)
这引起了:
.rb:221:in `send': wrong number of arguments (1 for 0) (ArgumentError)
from /usr/lib64/ruby/gems/1.9.1/gems/treetop-1.4.15/lib/treetop/runtime/compiled_parser.rb:18:in `parse'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/elements/address_list.rb:26:in `initialize'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/common/common_address.rb:9:in `new'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/common/common_address.rb:9:in `parse'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/common/common_address.rb:100:in `value='
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/structured_field.rb:29:in `initialize'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/from_field.rb:41:in `initialize'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:203:in `new'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:203:in `new_field'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:192:in `create_field'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/field.rb:119:in `initialize'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/header.rb:175:in `new'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/header.rb:175:in `[]='
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/message.rb:1184:in `default'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/message.rb:637:in `from'
/Mailer.rb:12:in `block in send'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/message.rb:132:in `instance_eval'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/message.rb:132:in `initialize'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/mail.rb:50:in `new'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/mail.rb:50:in `new'
我的代码中有什么想法错了吗?