Ruby Mail gem:连接被拒绝 - 连接(2)(Errno :: ECONNREFUSED)

时间:2012-04-29 18:05:34

标签: ruby email

我正在尝试使用Ruby mail 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使用的默认端口有关。

1 个答案:

答案 0 :(得分: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