Sending a basic "Weekly Digest" email from a Rails 3 application

I created a rake task to send emails to my subscribers (registered users).


desc "Send digest"
task :send_digest => :environment do
   Notifier.digest.deliver #if


Notifier :: digest

 def digest(periodicity = "weekly")

   @from = ""

   @bcc = ""
     User.where("digest_periodicity LIKE ?", periodicity).each do |u|
       @bcc += u.email_address + ","
   @bcc = Rails.env.production? ? @bcc[0..-1] : ""

   @message_subject = Rails.env.production? ? "#{periodicity.capitalize} Digest" : "#{periodicity.capitalize} Digest (Test)"

   @public_projects = PowerPlant.where("public = ?", true).order("created_at desc")  

   mail(:bcc => @bcc, :subject => @message_subject)



This works fine until I try to expand. In my work environment, the recipient list is over 300 email addresses. so when I run the correct rake command, instead of sending my email, I get this message.

$ heroku rake send_digest --app biowatts
> rake aborted!
> 452-4.5.3 Your message has too many recipients. For more information regarding


I am using but I also tried to use myaddydy smtp mail server but it looks like I will run into similar problems.

MY QUESTION: How do I periodically send an email to my subscribers list?

Note. This email is based on what's in my database ...

hope you can help,



source to share

1 answer

Your code is fine. The problem lies in the rules for gmail. You cannot send multiple emails at once. If you've ever had a friend's account hacked, you'll see them send an email to 100 or so recipients and repeat.

Solution: Have multiple emails and rotate (this is a bad idea because it will trigger other gmail spam protections)

Use regular contact or some other mailing list - Ideal for your situation

Use SendGrid - They will likely dump you as you are "spamming" in their eyes, even if you are not spam.



All Articles