如何通过带有rails的postfix邮件服务器发送邮件?

时间:2015-06-22 04:49:15

标签: ruby-on-rails email mailer

在我的本地主机上,我按照这篇文章制作了一个邮件服务器并且运行良好。

  

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

我想用rails框架开发邮件程序功能。以下是我的设置:

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

当我调用send mail方法时,我看到了这些错误:

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

我不确定我的配置文件是否合适。

1 个答案:

答案 0 :(得分:2)

您需要将delivery_method:smtp更改为:sendmail

config.action_mailer.delivery_method = :sendmail