views:

100

answers:

1

Hello people!

I would like to send a small amount of email from my app through Gmail. Now, the SMTP settings will be determined at runtime (ie: from the db), can this be done?

--- edit ---

I can set the ActionMailer subclass (named Notifier) smtp settings in one of the class' methods. This way I can set the username and password for sending the email dynamically. The only thing is that you have to set ALL the smtp_settings. Is it possible to set just the username & password settings in the class method?

This is the code I'm using right now, it is sending:

class Notifier < ActionMailer::Base
  def call(user)
    Notifier.smtp_settings = { 
      :enable_starttls_auto => true, 
      :address => "smtp.gmail.com",
      :port => "587",
      :domain => "mydomain.com",
      :authentication => :plain,
      :user_name => "[email protected]",
      :password => "password"
    }

    recipients user.email
    subject    "Test test"
    body       "Test"
  end
end

I would like to just set the username and pw here.

A: 

Since the configuration files are all Ruby, then the settings can easily be fetched from a configuration file or the like at runtime.

Here's a post I wrote a while back on getting ActionMailer working with GMail SMTP.

NOTE: If you're using rails 2.3 and Ruby 1.87, you don't need the plugin and can simply use the settings in this comment

Douglas F Shearer
Fabian