views:

47

answers:

1

Hi,

Currently for sending rails emails we use google apps for our emails, but we're limited to 500 emails/account/day.

I was wondering if there's any way to track how many emails we're sending, and then switch accounts if needed - as in, if we're under 500 emails for the day, use account 1, and if we've hit 500, use account 2, If we hit 999, use account 3 etc.

Is this possible? If there's a plugin that's awesome, if not, how would I go about doing this?

Thanks!

+1  A: 

You can easily accomplish this solution by creating a proxy class. The class will be responsible for getting the email delivery request, log the request and forward it to the appropriate Mailer.

This is a very simple prototype, assuming you are using Rails 2.

module MailerProxy

  mattr_accessor :emails_count
  @@emails_count = 0

  def self.deliver(klass, method, *args)
    emails_count += 1
    klass.send("deliver_#{method}", *args)
  end

end

MailerProxy.deliver(UserMailer, :email_notification, User.first)

Despite the solution above might work, I strongly encourage you to use an appropriate service for sending emails which is able to handle your daily rate instead of trying to create complex workarounds.

Simone Carletti
Thanks Simone! So far a lot of the emailing services out there seem to be expensive - postmark seems to be the cheapest - do you have any recommended sites?
stringo0
I am having trouble implementing this/thinking about it - 1) How do I specify which smtp to use? Do I need to set up multiple mailers? Also, it needs to be a class, correct?
stringo0
1. Create an array of options and let the class choose the best one. Of course, the example is just a prototype. No, you don't need multiple mailer, just change ActiveMailer settings. No, it doesn't need to be a class.
Simone Carletti