本文介绍了如何在 ActionMailer 中捕获错误异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是我如何在 ActionMailer 发送邮件时捕获异常.对我来说这听起来不可能,因为在这种情况下 ActionMailer 应该将邮件发送到邮件服务器,如果邮件服务器返回错误,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 中捕获错误异常
发布评论