How to send a mail by postfix mail server with rails?

1.2k views Asked by At

On my local host, I followed this article made a mail server and it works well.

https://www.digitalocean.com/community/tutorials/how-to-install-postfix-on-centos-6

I want to develop a mailer feature with rails framework. Here are my settings:

# mailer
config.action_mailer.default_url_options = { :host => 'example.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'localhost',
  port:                 25,
  domain:               'example.com'
}

When I call the send mail method, I saw these errors:

/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/2.2.0/net/protocol.rb:153:in `read_nonblock': end of file reached (EOFError)
  from /vagrant/user1/vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
  from /vagrant/user1/vendor/bundle/ruby/2.2.0/gems/actionmailer-4.2.0/lib/action_mailer/message_delivery.rb:85:in `deliver_now'

I am not sure is it right about my config file.

1

There are 1 answers

0
Amit Thawait On BEST ANSWER

You need to change the delivery_method from :smtp to :sendmail

config.action_mailer.delivery_method = :sendmail