如何使用 rails 通过 postfix 邮件服务器发送邮件?

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

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

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

当我调用发送邮件方法时,我看到了这些错误:

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

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

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

config.action_mailer.delivery_method = :sendmail