I'm using my Gmail Apps for Domain account to send email within my rails application for standard automated emails (user signup, forgot password, notify admin of new comment, etc), but I'm worried about the 500 emails per day limit set by Google.
Google suggests one way to overcome the limit is to use multiple user accounts.
So, I've setup 10 additional gmail user accounts (noreply1, noreply2, noreply3, etc) - I'd like to track when any of these accounts has sent 500 emails in a 24 hour period and use the idle account accordingly.
How do I dynamically set the :user_name
value in ActionMailer::Base.smtp_settings
?
Here's my current setup - NOTE: this sends from "noreply1" every time, even though i'm explicitly setting :user_name and :from to "noreply2":
--- development.rb ---
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "mydomain.com",
:authentication => :plain,
:user_name => "[email protected]",
:password => "password"
}
--- account.rb --- (MODEL, called via a callback)
after_create :send_welcome_email
...
def send_welcome_email
#ActionMailer::Base.smtp_settings[:user_name] = '[email protected]'
ActionMailer::Base.smtp_settings.merge!({:user_name => "[email protected]"})
SubscriptionNotifier.deliver_welcome(self)
end
--- subscription_notifier.rb --- (MODEL)
class SubscriptionNotifier < ActionMailer::Base
def welcome(account)
@sent_on = Time.now
@subject = "Welcome to the App"
@recipients = account.email
@from = "[email protected]"
@body = { :account => account }
end
end