ActionMailer (http://wiki.rubyonrails.org/rails/pages/ActionMailer) makes sending e-mail more high-level than using the SMTP protocol (or net/smtp) directly. Instead of talking directly with an SMTP server, you create a descendent of ActionMailer::Base, implement a method that sets your mail’s subject, recipients, and other details, and then you call that method to send e-mail.
ActionMailer is a part of the Ruby on Rails framework (as covered in Chapter 13), but can be used independently of it. If you don’t have Ruby on Rails installed on your computer yet, you can install the ActionMailer gem with gem install actionmailer.
Here’s a basic example of using ActionMailer:

require ‘rubygems’
require ‘action_mailer’
class Emailer < ActionMailer::Base def test_email(email_address, email_body) recipients(email_address) from "me@privacy.net" subject "This is a test e-mail" body email_body end end Emailer.deliver_test_email('me@privacy.net', 'This is a test e-mail!') [/source]

Advertisements