Tuesday, December 25, 2007

Quick ActionMailer tips

To include your helpers (defined in application_helper.rb), do a
helper :application
in the mailer class defined in app/models.

To be able to use url_for and restful route helpers in the ActionMailer model, do an include ActionController::UrlWriter and set default_url_options[:host] to your host.
If you want to use html_escape (h) in html email templates, feel free. html_escape is defined in ERB, so it is already available.

To add a Return-Path header

To disble ActionMailer from printing in the production log,
ActionMailer::Base.logger = nil

I want to send an email to multiple users, but not show other email addresses in the To line. For now I am simply looping over the emails and sending a seperate email
by calling Mailer.deliver_ method for each email addresses. I can easily imagine this to be a configuration option to ActionMailer so it can do this looping itself.

This is a good read on the topic.

No comments: