varatis
varatis

Reputation: 14740

Ruby Mail gem: Connection refused - connect(2) (Errno::ECONNREFUSED)

I'm trying to just do a simple mail delivery with the Ruby mail gem:

require 'mail'
Mail.deliver do
   from    '[email protected]'
   to      '[email protected]'
   subject 'Here is the image you wanted'
   body    File.read('body.txt')
end

But I get this error:

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>'

How can I fix this? I'm assuming it's something having to do with the default port Mail works with.

Upvotes: 2

Views: 5862

Answers (1)

varatis
varatis

Reputation: 14740

Ok figured it out.

Sendmail wasn't running so I started it up, and changed these lines:

require 'mail'
mail = Mail.new do
  from     '[email protected]'
  to       '[email protected]'
  subject  'Here is the image you wanted'
  body     File.read('body.txt')
end

mail.delivery_method :sendmail

mail.deliver

Upvotes: 3

Related Questions