This Rails example shows how to send an email for user signups. You can also checkout this Ruby gem for more advanced features.
Info
This example is specific to ActionMailer. You can use any SMTP library that is compatible with Rails, but the configuration may be slightly different.
In config/environment.rb specify ActionMailer defaults
Warning
As a best practice, you should not store your credentials directly in
the source but should instead store them in configuration files or
environment variables. See this tutorial on environment
variables in rails.
Create your notification model in app/models/notifier.rb
classNotifier<ActionMailer::Basedefault:from=>"any_from_address@example.com"# send a signup email to the user, pass in the user object that contains the user's email addressdefsignup_email(user)mail(:to=>user.email,:subject=>"Thanks for signing up")endend
In the controller in app/controllers/users_controller.rb add
classUsersController<ApplicationControllerdefcreate# Create the user from params@user=User.new(params[:user])if@user.save# Deliver the signup_emailNotifier.signup_email(@user).deliverredirect_to(@user,:notice=>"User created")elserender:action=>"new"endendend