3

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.

mudit mehrotra
  • 71
  • 1
  • 11
  • http://stackoverflow.com/questions/4313177/sending-mail-with-rails-3-in-development-environment – denis.peplin Jul 26 '12 at 13:17
  • By default `config.action_mailer.raise_delivery_errors=false` for development environment which means rail will not attempt to send email but you still can view the entire email in the log file for verification. So first make this property value to true, restart the server and try to send again. This may help you to find the problem by analysing logs. – Amit Patel Jul 26 '12 at 16:49
  • i still stuck with the same problem sent mail entry added in development.log file but not shown in my inbox i also done config.action_mailer.raise_delivery_errors=true but its not working your suggestion are welcome – mudit mehrotra Jul 27 '12 at 08:18
  • ohhh i have done that by specifying smtp settings in development.rb file code is 'config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :domain => 'triffort.com', :user_name => 'your full mail address', :password => 'your password', :authentication => 'plain', :enable_starttls_auto => true }' – mudit mehrotra Jul 27 '12 at 11:01

1 Answers1

2

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.

Tass
  • 1,628
  • 16
  • 28