如何在開發中禁用ActionMailer?

[英]How to disable ActionMailer in Development?


sometimes when I am developing, I do not have an internet connection. This results in an error wherever my app is supposed to send an email:

有時當我開發時,我沒有互聯網連接。這會導致我的應用程序發送電子郵件時出錯:

getaddrinfo: nodename nor servname provided, or not known

Is there a simple and quick way where i can change a config value to make ActionMailer just not try to actually send out an email and not throw an error? Maybe something thats scoped to the development environment. Or some other way I can avoid the error being thrown and my code passing wherever I call the actionmailer deliver?

有沒有一種簡單快捷的方法,我可以更改配置值,使ActionMailer不嘗試實際發送電子郵件,而不是拋出錯誤?也許是開發環境的一些東西。或者其他一些方法我可以避免錯誤被拋出,我的代碼傳遞到我稱之為actionmailer的地方?

I'm using Rails 3.1

我正在使用Rails 3.1

2 个解决方案

#1


50  

It's common practice to just let Rails ignore the mail errors. In your config/environments/development.rb file add, uncomment or modify:

通常的做法是讓Rails忽略郵件錯誤。在config / environments / development.rb文件中添加,取消注釋或修改:

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

You can also set this:

你也可以這樣設置:

config.action_mailer.perform_deliveries = false

See the documentation here http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration

請參閱此處的文檔http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration

You can also set the delivery method to :test, but I have not actually tried that

您還可以將交付方式設置為:test,但我還沒有嘗試過

config.action_mailer.delivery_method = :test

#2


12  

If you want to disable mail deliveries after your rails app has been initialized (while creating sample data, during migrations, etc.):

如果要在初始化rails應用程序后(在創建示例數據時,在遷移期間等)禁用郵件傳遞:

ActionMailer::Base.perform_deliveries = false

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/10/11/68197cf6a401414a89e1cca4db58b4ce.html



 
  © 2014-2022 ITdaan.com 联系我们: