Posts Tagged ‘2.3.4’

Sending Email from Multiple Google Apps Accounts

20 October 2009 by Bret

PROBLEM: We need to be able to send emails from multiple accounts using Rails 2.3.4 and Google Apps. Our code was mostly correct, it worked in development because the ActionMailer classes were being loaded with each request. But in production all the emails were coming from one account, the account defined in the last mailer model file, for us UserMailer.

SOLUTION: The patch attached in the second post. The patch fixes actionmailer/lib/action_mailer/base.rb. No need for details on why other than to say smtp_settings and sendmail_settings are changed into superclass_delegating_accessor’s so that mail settings can be changed in each mail class.

This is needed especially when using Google Apps Standard because Google limits outgoing email to 500 per account per day.

After patching the base.rb file, we add our code to our production environment file.

ActionMailer::Base.smtp_settings = {
 :address => "smtp.gmail.com",
 :port => 587,
 :domain => "domain.com",
 :user_name => "default@domain.com",
 :password => "password",
 :authentication => :plain,
 :enable_starttls_auto => true
}

We tried just assigning the user_name and password in the mailer class and got errors with our smtp_tls code were using, so we just duplicate all the other settings as well and it works. Our sample_mailer.rb code:

SampleMailer.smtp_settings = {
 :address => "smtp.gmail.com",
 :port => 587,
 :domain => "domain.com",
 :user_name => "contact@domain.com",
 :password => "password",
 :authentication => :plain,
 :enable_starttls_auto => true
}

This way we can now send from whatever email account we need to for each mailer.

Ruby on Rails 2.3.4 not playing well with Ruby 1.9.1

6 September 2009 by Bret

I was hoping upgrading from Rails 2.3.3 to 2.3.4 was going to be a breeze. Nope. Apparently, there are some issues with Rails 2.3.4 and Ruby 1.9.1 as detailed in this lighthouse ticket.

The problem is in the active_support-2.3.4/lib/active_support/message_verifier.rb file. When you try and login to your Rails app you’ll receive an error like:
undefined method `^' for "9":String

I won’t get into the details as to what’s breaking, that’s for those much smarter than I.

Basically if you’re using Ruby 1.9.1, you might be better off not upgrading to 2.3.4 as your application will break. I applied the patch in the ticket and all works now, but what a pain. Seems like something that should have been tested before 2.3.4 was released. Others have had the same issue as well.

To apply the patch I downloaded the patch from the lighthouse ticket above to my desktop and then used:
cd /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4
sudo patch -p1 < /local/path/to/patch/0001-ruby-1.9-friendly-secure_compare.patch

The file that needed to be patched couldn't be found so i got:
File to patch:
Where I entered the path to the file:
lib/active_support/message_verifier.rb

The patch then applied and I was once again able to login to my application.