10/24/2013 - 12:12 AM


# There are 4 basic steps to implementing your ActionMailer functionality in a Rails app:
# Step 1. Create your ActionMailer object. Remember that it can have any name, but should finish with "Mailer":

rails g mailer UserMailer 

class UserMailer < ActionMailer::Base
  default from: ""

   def confirm_user(user)
    @user = user
    @url  = ''
    mail(to:, subject: 'Welcome to Fred Site')

# Step 2. Create your HTML and text version of your email body:

Text version of greeting email (in views/UserMailer/welcome_email.text.erb )
Welcome to, <%= %>
You have successfully signed up to,
your username is: <%= @user.login %>.
To login to the site, just follow this link: <%= @url %>.
Thanks for joining and have a great day!

HTML version (in views/UserMailer/welcome_email.html.erb)
<!DOCTYPE html>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
    <h1>Welcome to, <%= %></h1>
      You have successfully signed up to,
      your username is: <%= @user.login %>.<br/>
      To login to the site, just follow this link: <%= @url %>.
    <p>Thanks for joining and have a great day!</p>

# Step 3. Add the call to your mailing method found in your ActionMailer object to your controller.
# This can be any action you want to trigger a message being sent from. The most common place will
# be your create method:
def create
    @user =[:user])
    respond_to do |format|
        # Tell the UserMailer to send a welcome Email after save
        # only send the message if the user is successfully saved
        format.html { redirect_to(@user, notice: 'User was successfully created.') }
        format.html { render action: 'new' }

# Step 4. Update your configuration environment. If you are in development (on your machine) you will use the
# development.rb file settings. In Heroku you will use production.rb. The settings will depend on where you
# are deploying from

Then the configuration files:
for local testing in config/environment/development.rb put something like this:
config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
#   location: '/usr/sbin/sendmail',
#   arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: ''}

You will use the config/environment/production.rb file for deployment to Heroku, and 
use the environment variables suggested by SendGrid, or whoever you choose for your
3rd party mailer service.