在Rails 3中使用mailcatcher

时间:2012-09-23 18:14:40

标签: ruby-on-rails-3 actionmailer

我想使用mailcatcher来检查我的邮件是否已发送。他们不是,我想知道为什么,因为邮件生成并且肯定被称为。

所以在我的config / enviroment / 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

邮件当然是邮件运行的。那邮件为什么不发送?

2 个答案:

答案 0 :(得分:13)

我发现,我使用错误的SMTP地址进行开发环境。它必须是

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

而不是

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

答案 1 :(得分:2)

https://github.com/sj26/mailcatcher/issues/182

$ mailcatcher -f -v
Starting MailCatcher
==> smtp://127.0.0.1:1025
==> http://127.0.0.1:1080
==> SMTP: Received message from '<donotreply@xxx.com>' (676 bytes)