Background thread for email sending in Ruby on Rails -


i need run background thread in ruby on rails application should send emails when date has occurred, depending on values in db (and email body should contain info db).

what best way achieve such behavior?

i'm using ruby on rails 4.1.4 btw.

thanks in advance.

you can use whenever gem perform background jobs according requirement. check out github docs here. whenever

ryan bates created great railscast whenever: cron jobs intro in rails

in config/schedule.rb

every 2.hours   runner user.send_email_to_users end 

in user model

def self.send_email_to_users   //write logic here , call action send mails.   usermailer.send_mail_persons(user).deliver    //pass other data if required in arguments. end 

in app/mailers/user_mailer.rb

def send_mail_persons(user)   @user = user   mail :to => @user.email, :subject => "amusement.", :from => mail_address 

end

create html template per requirement, app/views/user_mailer/send_mail_persons.html.erb


Comments

Popular posts from this blog

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -