How to catch error exception in ActionMailer

前端 未结 5 824
误落风尘
误落风尘 2020-12-05 00:58

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, a

5条回答
  •  误落风尘
    2020-12-05 01:32

    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 "/"
    

提交回复
热议问题