Reputation: 7419
Say you have a mailer with an action in Rails, being called from some model using delay
, for example:
class ReportMailer < ActionMailer::Base
default from: "[email protected]"
def order_received(order)
@order = order
mail(:to => @order.shop.email, :subject => "You have a new order on Shopstar")
end
end
order.rb:
if self.shop.email_preference.on_order?
ReportMailer.delay.order_received(self) unless self.source == "pos"
end
Will this send the mail from a development environment?
and
Will this send the mail in the production version?
Upvotes: 2
Views: 3458
Reputation: 5839
delayed job workers need to be running,
RAILS_ENV=development bundle exec bin/delayed_job start
You may face that error:
bash: bin/delayed_job: No such file or directory
So you will have to generate the bin/delayed_job file running that command:
bundle exec rails generate delayed_job
RAILS_ENV=production bin/delayed_job start
Above commands are for Rails 4. For Rails 3, you should do:
script/delayed_job
instead of bin/delayed_job
Check delayed_jobs page for more details
Upvotes: 8
Reputation: 5111
First let me answer your second question to send mail from your system whether live/development, you need smtp settings. For SMTP settings example you can took a look at http://guides.rubyonrails.org/action_mailer_basics.html .
Secondly, this configuration settings goes in one of the environment files. In which environment file it goes depends on which environment your application is running. If your live server is running in development environment then these changes will be made in config/environments/development.rb
Hope that clarifies.
Upvotes: 0
Reputation: 76774
Will this send the mail from a development environment?
It will send an email depending on your STMP settings
Rails has settings for config.action_mailer
, which you can define in both config/environments/development.rb
& config/environments/production.rb
:
#config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "************.co.uk",
:user_name => "****@gmail.com",
:password => ENV["gmail"],
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { :host => "localhost:3000"}
Whichever environment you run delayed_job
on, you need to be sure these details are set up in your environment config files
Upvotes: 0
Reputation: 34774
With an unchanged environment configuration then it won't send emails in development and it will send emails in production.
You should see something like this in config/environments/development.rb
:
config.action_mailer.perform_deliveries = false
Which prevents emails from being sent in your development environment. You can find more details on the configuration options for action mailer in the configuration guide
Don't forget if you are delaying sending messages then you need your delayed jobs to be processed too.
Upvotes: 0
Reputation: 1665
Will this send the mail from a development environment? Will this send the mail in the production version?
Its all depends on your environment smtp setting in each file (development.rb,production.rb)
In order to use delayed job in your environment requires running worker to handle this in background. Try look at foreman gem to help you which can run server and worker just using foreman start.
Upvotes: 0