Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch error exception in ActionMailer

The problem is how can I catch exception in delivering mail by ActionMailer. For me it sounds impossible, because in this case ActionMailer should sent mail to mailserver, and if mailserver returns error, ActionMailer should show me this error. I am interested only in counting undelivered mails.

Do you have any ideas how to implement this? Thanks!

like image 477
com Avatar asked Jan 03 '12 09:01

com


2 Answers

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[:success] = "Utente #{@user.name} creato. Problems sending mail"       end       redirect_to "/" 
like image 142
piffy Avatar answered Nov 01 '22 08:11

piffy


This should work in any of your environment files. development.rb or production.rb

config.action_mailer.raise_delivery_errors = true
like image 38
Sukeerthi Adiga Avatar answered Nov 01 '22 09:11

Sukeerthi Adiga