Action Mailer

signup

Actiion Mailer Tutorial on Rails 3

Action Mailer has been rewrite in Rails 3 , I assuming that you have the User model, and then I’ll generate a new mailer with the following code

   rails g mailer user_mailer

app/mailers/user_mailer.rb

class UserMailer < ActionMailer::Base
default :from => "slametnhd@gmail.com"

  def registration_confirmation(user)
    @user = user
    mail(:to => user.email, :subject => "Registered")
  end
end

/config/initializers/setup_mail.rb

ctionMailer::Base.smtp_settings = {
 :address              => "smtp.gmail.com",
:port                 => "587",
 :domain               => "mail.gmail.com",
 :user_name            => "slametnhd@gmail.com",
  :password             => "secret",
  :authentication       => "plain",
 :enable_starttls_auto => true
 }

 ActionMailer::Base.default_url_options[:host] = "localhost:3000"

/app/views/user_mailer/registration_confirmation.text.erb

Thank you for registering!
<%= @user.name %>

Sincerely for you

masmet.com

app/controllers/user_controller.rb

def create
      @user = User.new(params[:user])
      if @user.save
        UserMailer.registration_confirmation(@user).deliver
        sign_in @user
        flash[:success] = "Welcome to the Masmet App!"
        redirect_to @user

      else
        @title ="sign up"
        render 'new'
      end
    end

gmail

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s