如何在ActionMailer中捕获错误异常 [英] How to catch error exception in ActionMailer

查看:116
本文介绍了如何在ActionMailer中捕获错误异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是如何在ActionMailer发送邮件时捕获异常。对我来说听起来是不可能的,因为在这种情况下,ActionMailer应该发送邮件到mailserver,如果mailserver返回错误,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!

推荐答案

我在控制器中使用这样的东西:

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

这篇关于如何在ActionMailer中捕获错误异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆