Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

I'm using Rails 3.1

like image 406
alik Avatar asked Oct 11 '11 17:10

alik


People also ask

What is Action_ Mailer in rails?

Action Mailer is the Rails component that enables applications to send and receive emails. In this chapter, we will see how to send an email using Rails. Let's start creating an emails project using the following command. tp> rails new mailtest. This will create the required framework to proceed.

How do I view Mailers in Rails?

Mailer views are located in the app/views/name_of_mailer_class directory. The specific mailer view is known to the class because its name is the same as the mailer method. In our example from above, our mailer view for the welcome_email method will be in app/views/user_mailer/welcome_email. html.


2 Answers

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

# 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

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

config.action_mailer.delivery_method = :test 
like image 122
Wizard of Ogz Avatar answered Sep 18 '22 19:09

Wizard of Ogz


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

ActionMailer::Base.perform_deliveries = false 
like image 20
dhulihan Avatar answered Sep 21 '22 19:09

dhulihan