Reputation: 71
I know that this is a simple question and asked by many more many times and i also asked this because all the previous one i have checked is based on rails 3.0.0 version and i am using the latest one. I have a user registration form which contain name and email fields. I want to do that when a user click on the submit button an email should be sent to the specified email address by the user i am using rails 3.2.5 version and gem 'mail' version 2.4.4 development log file shows that mail is sent to the email address but its not find in the inbox. I also know that during the development mode action mailer doesn't sent a mail to any address but i want to do this during the development phase. My code is :
/config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "asciicasts.com",
:user_name => "asciicasts",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
/app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "eifion@asciicasts.com"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end
/app/controllers/users_controller.rb
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.registration_confirmation(@user).deliver
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
so anyone please help me.
Upvotes: 3
Views: 2172
Reputation: 1628
I'd run into something like this recently as well.
From config/environments/development.rb
:
config.action_mailer.perform_deliveries = true
# This entry made me think the emails should be sent, they were prior to an upgrade by a fellow developer.
I also found these emails were not being sent. Digging around, I found config/email.yml
It looks like this:
development:
:delivery_method: test
:settings:
:address: <email_server_address>
:port: 25
When I changed :delivery_method: test
to :delivery_method: sendmail
(which is what we use at my company), it began working.
To summarize, I found that the settings in config/email.yml
are evaluated last and will trump whatever's in your individual environment file.
Upvotes: 2