views:

46

answers:

1

I've got Google Apps setup with email for my domain, and now I need to configure ActionMailer to use it. But the info I've found seems to be conflicting. Can anyone tell me how exactly to set it up with Rails 2.3.5?

+1  A: 

I faced the same problems and got it working with this:

Step 1. Add the following to your development environment:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.smtp_settings = {
  :enable_starttls_auto => true,
  :address            => "smtp.gmail.com",
  :port               => "587",
  :domain             => "domain.com",
  :authentication     => :plain,
  :user_name          => "YOUR_USER_NAME", #should be [email protected]
  :password           => "YOUR_PASSWORD_HERE"
}

The critical line is :enable_starttls_auto. You have to restart webrick after making changes here.

Step 2. Create a Model like project_mailer.rb

class ProjectMailer < ActionMailer::Base

  def confirmation(project)
    subject    'Your email subject'
    recipients project.email
    from       '[email protected]'

    body       :project => "hi"
  end
end

Step 3. Create a View like /views/project_mailer/confirmation.html.haml (or .erb). This is just a standard view file.

Step 4. Add a line in your controller like:

ProjectMailer.deliver_confirmation(@project)
Michael C