The purpose of life is not to win. The purpose of life is to grow and to share. When you come to look back on all that you have done in life, you will get more satisfaction from the pleasure you have brought into other people's lives than you will from the times that you outdid and defeated them.

Send Email with Rails using GMail

Let us use GMail SMTP server for testing.

Step 1:

Please include the below code in environment.rb file under /config folder.

# environment.rb

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default_content_type = "text/html"

ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "localhost",
:authentication => :plain,
:user_name => "google_username",
:password => "google_password",
}

Step 2:

Generate Mailer model using the below command.

ruby script/generate mailer registration

Step 3:

Now your registration.rb model file should like below. Include the method welcome in class Registration.

class Registration < ActionMailer::Base def welcome(name, email) @recipients = "user@host.com" @from = params[:contact][:email] headers "Reply-to" => "#{email}"
@subject = "Welcome to Add Three"
@sent_on = Time.now
@content_type = "text/html"

body[:name] = name
body[:email] = email
end

end