This is a brief guide to sending email in Rails. See how to configure the environment, generate a mailer, create a template, and deliver the mail.
# config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp
# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => 'smtp.example.com',
:port => 25,
:domain => 'www.example.com',
:authentication => :login,
:user_name => 'www',
:password => 'secret'
}
# users_controller.rb
UserMailer.deliver_registration_confirmation(@user)
# user_mailer.rb
def registration_confirmation(user)
recipients user.email
from "webmaster@example.com"
subject "Thank you for Registering"
body :user => user
end
<!-- registration_confirmation.rhtml -->
Hi <%= @user.name %>, ...