views:

264

answers:

1

I am using Action Mailer and have my configuration settings for Action Mailer in my environment.rb file. I would like to post my project in a public repository along with an environment.rb file, but I do not want to include my mail server's login information. How does one configure Capistrano's deploy.rb so that it prompts the user for the mail server settings and then modifies or creates an environment.rb file during Capistrano's deployment.

Thanks for looking =)

+1  A: 

There are lots of other variations on this... see this blog post for more ideas: http://www.simonecarletti.com/blog/2009/06/capistrano-and-database-yml

Here a start...

Add this into your production.rb environment file:

ActionMailer::Base.smtp_settings = File.expand_path(File.join(RAILS_ROOT, 'config', 'actionmailer.yml'))

And in a capistrano task, you can do something like this:

desc "Generate actionmailer.yml file" 
task :generate_actionmailer_yml, :roles=>:app do
  secret_password = Capistrano::CLI.ui.ask "Enter your secret mail password:"

  template = File.read("config/deploy/actionmailer.yml.erb")
  buffer = ERB.new(template).result(binding)
  put buffer, "#{shared_path}/config/actionmailer.yml"
end

desc "Link actionmailer.yml from shared" 
task :link_actionmailer_yml, :roles=>:app do
  run "rm -f #{current_path}/config/actionmailer.yml && ln -s #{shared_path}/config/actionmailer.yml #{current_path}/config/actionmailer.yml"
end

after "deploy:finalize_update", "deploy:link_actionmailer_yml"

Then, you create a template actionmailer.yml.erb file:

address: "my.smtp.com"
port: 587
authentication: :plain
user_name: "[email protected]"
password: <%= secret_password %>
jkrall