Ruby on rails 3 在Rails 3中使用mailcatcher

Ruby on rails 3 在Rails 3中使用mailcatcher,ruby-on-rails-3,actionmailer,Ruby On Rails 3,Actionmailer,我想用它来检查我的邮件是否已发送。它们不是,我想知道为什么,因为邮件程序是生成的,并且肯定是调用的 因此,在我的config/environment/development.rb中,我写道: config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "loca

我想用它来检查我的邮件是否已发送。它们不是,我想知道为什么,因为邮件程序是生成的,并且肯定是调用的

因此,在我的config/environment/development.rb中,我写道:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
我的电话是这样的:

OrderMailer.send_new_order(@order).deliver
class OrderMailer < ActionMailer::Base
  default from: "from@example.com"
  def send_new_order(order)
    @greeting = "Hi"
    mail to: "to@example.org", subject: "Test"
  end
end
最后生成的控制器如下所示:

OrderMailer.send_new_order(@order).deliver
class OrderMailer < ActionMailer::Base
  default from: "from@example.com"
  def send_new_order(order)
    @greeting = "Hi"
    mail to: "to@example.org", subject: "Test"
  end
end
类OrderMailer
当然,还有mailcatcher。那么为什么邮件没有发送呢?

我发现,我在开发环境中使用了错误的SMTP地址

一定是这样

config.action_mailer.smtp_settings = { :address => "127.0.0.1", :port => 1025 }
而不是

config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }

我发现,我为开发环境使用了错误的SMTP地址

一定是这样

config.action_mailer.smtp_settings = { :address => "127.0.0.1", :port => 1025 }
而不是

config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }

$mailcatcher-f-v
启动邮件收集器
==> smtp://127.0.0.1:1025
==> http://127.0.0.1:1080
==>SMTP:从“”接收邮件(676字节)

$mailcatcher-f-v
启动邮件收集器
==> smtp://127.0.0.1:1025
==> http://127.0.0.1:1080
==>SMTP:从“”接收邮件(676字节)

这有什么原因吗?为什么localhost不能工作,而127.0.0.1不能工作。@AnonJ我想它只需要一个ip或url,所以localhost不能解析任何内容。也许会有效果,也许我稍后会检查。这有什么原因吗?为什么localhost不能工作,而127.0.0.1不能工作。@AnonJ我想它只需要一个ip或url,所以localhost不能解析任何内容。也许会有用,也许我以后再查。