Testing Active_Mailer with GMail in development

Problem
You want to test your email configuration and be able to send emails in your development environment, using a GMail account in a Rails application using 2.3.2.

Solution
Start your console in your development environment:

./script/console

Add the following replacing your GMail details:


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

Add a simple email class:


class MyMailer < ActionMailer::Base def test_email @recipients = "an_address_to_sent_to@domain.com" @from = "address_from@your_google_domain.com" @subject = "test from dev console" @body = "this is the body" end end

and to finally test the email:


MyMailer::deliver_test_email

if it doesn't return with an error but with something like:


TMail::Mail port=#TMail::StringPort:id=0x..fdab4cee0 bodyport=#TMail::StringPort:id=0x..fdab4a9ec

then it should be working so add the configuration to your environments/development.rb

config.action_mailer.smtp_settings { ... }

Freezing rails to an older version using gems

Problem
You want to deploy to a shared host (dreamhost) that has a later version of rails from the one you have developed your application.
You also have a later version installed in your development pc,and using rake rails:freeze:gems uses the latest one and not the one you want.

Solution
Use the following to freeze the specific version you want, and by using your gems you have installed:
rake rails:freeze:gems VERSION=2.3.2