2012-09-23 75 views
0

我想使用mailcatcher来检查我的邮件是否被发送。他们没有,我想知道为什么,因为邮件是生成,并确定呼吁。在Rails 3中使用mailcatcher 3

所以在我的config /环境/ 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: "[email protected]" 
    def send_new_order(order) 
    @greeting = "Hi" 
    mail to: "[email protected]", subject: "Test" 
    end 
end 

和mailcatcher当然运行。那么邮件为什么不发送?

回答

12

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

它必须是

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

代替

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

是否有什么原因呢?为什么本地主机在127.0.0.1时没有工作。 –

+0

@AnonJ我想它只是预期的IP或网址,所以本地主机没有解决任何问题。也许http:// localhost会起作用,也许我会稍后再检查一下。 –