Wednesday, November 7, 2012

Rails SMTP email setup

I am using rails 3.2.6.

To setup SMTP email using ruby:

1. Add the following code into the /config/environment.rb

require File.expand_path('../application', __FILE__)

# Initialize the rails application AppName::Application.initialize!

ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.smtp_settings = {
:address => "smtp.host.com",
:port => 587,
:user_name => "email host",
:password => "email password hot",
:authentication => :plain,
:enable_starttls_auto => "true"
}

ActionMailer::Base.raise_delivery_errors = true

2. Create /app/mailers/appnamemailers.rb with the following content
class Appnamemailers < ActionMailer::Base
default :from => "email@hostemail.comd"


def welcome_email()
@url = "http://www.example.com"
mail(:to => "test@gmail.com", :subject => "Welcome to rails app")
end
end
2. To test run rails console
3. Execute the command Appnamemailers.welcome_email().deliver

No comments:

Post a Comment