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, e
Store the available usernames in a table in the database, along with a 'last-modified', 'last-reset' and a sent count. You can then query this when sending an email to find the least used email address currently. Then increment the sent count and last-modified account. The 'last-reset' value can be used for your cleanup code so that you reset the counts each 24 hour period.
This also makes it easy to add new email accounts, retire accounts you aren't using anymore, implement in a different app, etc. as it's all just in a database table that you can change when required.
The comment box was becoming too restrictive for my questions. Changing the ActionMailer::Base.smtp_settings
hash dynamically works as expected for me, so I suspect there is some other factor at play here. Some things to try:
Edit: more things to try
I'd have a good look at that smtp_tls.rb file mentioned in the comments to make sure nothing's hard-coded. Or remove it and try the plugin I linked above. To use it, you just need to add :tls => true
to the smtp_settings hash.
You should be able to set the :user_name element in the hash in the mailer in the same fashion as in the configuration, namely by doing:
ActionMailer::Base.smtp_settings[:user_name] = 'new_user_name'
Although this may require some extra code to force a reload of any internal action mailer config (not tested this myself)
You could also set up an MTA on your server and use that for sending the mail.
That's what we do.
You have to add your server's IP as a valid one for sending email in your domain's SPF record to avoid getting marked as spam.
Another benefit of this is that if you do this, you can set the From: address of the email to be one of your users, which you cannot do with GMail.