On Aug 20, 2009, at 1:51 PM, Aldo Italo wrote:
> > i need to send massive emails to various customers, > here 2 solutions i have think: > > > 1- > > customers = Customer.find(:all, :conditions => "newsletter = 1") > customers.each do |c| > @email = c.email > Mailer.deliver_send_newsletter(@subject, @email, @notice_id) > end > > > 2- > customers = Customer.find(:all, :conditions => "newsletter = 1") > customers.each do |c| > addresses << c.email+", " > end > @emails=addresses.join.gsub(/(, )$/, '') > Mailer.deliver_send_newsletter(@subject, @emails, @notice_id) > > > what is the right solution ? Hard to say without knowing how many customers that query is going to return... if it's under a 100 it doesn't matter. Under a 1000 it probably doesn't matter. If it's 10,000 and it's once a week, neither is going to be very fun. Keep in mind that those queries will instantiate however many objects that match... you could suck up a lot of memory... at least use the new find/block stuff. Might want to look into ar_mailer (ruby stuff), bulk_mailer (stand alone) and if your volume is high one of the companies that does this for a living so you don't have to deal with ending up on aol/msn/ yahoo's spam blacklists... -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---