2

我正在尝试使用 Ruby邮件gem 进行简单的邮件传递:

require 'mail'
Mail.deliver do
   from    'me@test.lindsaar.net'
   to      'varatis@gmail.com'
   subject 'Here is the image you wanted'
   body    File.read('body.txt')
end

但我得到这个错误:

Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `open'
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `tcp_socket'
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:555:in `block in do_start'
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:58:in `timeout'
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:555:in `do_start'
from /Users/varatis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
from /Users/varatis/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
from /Users/varatis/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.4.4/lib/mail/message.rb:2034:in `do_delivery'
from /Users/varatis/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.4.4/lib/mail/message.rb:231:in `deliver'
from /Users/varatis/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.4.4/lib/mail/mail.rb:140:in `deliver'
from mailer.rb:2:in `<main>'

我怎样才能解决这个问题?我假设这与 Mail 使用的默认端口有关。

4

1 回答 1

3

好的,想通了。

Sendmail 没有运行,所以我启动了它,并更改了这些行:

require 'mail'
mail = Mail.new do
  from     'me@test.lindsaar.net'
  to       'varatis@yahoo.com'
  subject  'Here is the image you wanted'
  body     File.read('body.txt')
end

mail.delivery_method :sendmail

mail.deliver
于 2012-04-29T18:20:39.460 回答