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

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

digest.rake:

desc "Send digest"
task :send_digest => :environment do
   Notifier.digest.deliver #if Time.now.monday?
end

      

Notifier :: digest

 def digest(periodicity = "weekly")

   @from = "biowatts@gmail.com"

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

   @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)

      

end

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 smtp.gmail.com 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,

Joel

+3


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.

+2


source







All Articles