John
John

Reputation: 4706

ActionMailer debugging

I'm trying to use Action Mailer in Rails to send email to users.

def create
  ...
  if @post.save
    UserMailer.archive_confirmation(@site).deliver
  end
end

But when I try it, I don't get any email, and I have no idea how to debug (since the create method runs successfully, and everything else goes as expected, there's no error message) Where could ActionMailer go wrong?

Upvotes: 2

Views: 4871

Answers (3)

Algorini
Algorini

Reputation: 874

In your respective environment file:

  ## config/environments/development.rb
  config.action_mailer.raise_delivery_errors = true

Upvotes: 0

Mohammad Shahnawaz
Mohammad Shahnawaz

Reputation: 876

If I am writing the code to sent the email in controller i can write like these to handle the rescue in my application and i can display the error message that is come in rescue we can display. I'm using something like this in the controller:

if @user.save
  begin
  UserMailer.welcome_email(@user).deliver
  flash[:success] = "#{@user.name} created"
  rescue Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e
  flash[:notice]=e.message   
  end
  redirect_to home_index_path
end

Upvotes: 0

Adam Eberlin
Adam Eberlin

Reputation: 14205

Check your RAILS log, APP_ROOT/log/development.log or APP_ROOT/log/production.log.

Upvotes: 2

Related Questions