In my post Leave a project how you would like to find it, I discussed how to leave a project with a great README. I added another item to that, how to preview emails. When handing off a project to a designer to skin, an issue that arises is previewing the application emails.
In his Scaling Labs video, Greg Pollack suggests handing of application emails to an email service provider. I think that is a great idea, but sometimes if you are working on a short lived website that might be over kill. So my solution is to create a rake that a designer can easily use. Here's my recipe:
- Create a separate config/mail.rb environment based on development.
- Append config.action_mailer.delivery_method = :sendmail to the file.
- Configure your database.yml with the same settings as your development environment.
- Write your rake tasks.
Here an (edited) example of the rake task I wrote (lib/application.rake):
desc %{Sends test notification Must specify RAILS_ENV=mail EMAIL=you@example.com to specify email address} task :send_notification => :environment do |t| registration = OpenStruct.new registration.first_name = Faker::Name.first_name registration.last_name = Faker::Name.last_name registration.email_address = ENV['EMAIL'] CompetitionMailer.deliver_notification(registration) end
Now run rake send_notification RAILS_ENV=mail EMAIL=nicholas@example.com. Check your email inbox!
Platform notes:
- Rails 2.3.8
- Mac OS X
There are other solutions that you may be interested in as well: