2012-02-08 79 views

回答

3

取決於您如何發送郵件的設置。如果您通過smtp發送郵件,ActionMailer使用Net::SMTP。在那裏你會發現可能引發的錯誤。

如果您的應用程序配置爲使用sendmail,ActionMailer使用IO

3

我們發現這個名單非常有效的,你可能要重新對標準誤差:

[ EOFError, 
IOError, 
TimeoutError, 
Errno::ECONNRESET, 
Errno::ECONNABORTED, 
Errno::EPIPE, 
Errno::ETIMEDOUT, 
Net::SMTPAuthenticationError, 
Net::SMTPServerBusy, 
Net::SMTPSyntaxError, 
Net::SMTPUnknownError, 
OpenSSL::SSL::SSLError 
] 

注我沒有包含Net::SMTPFatalError,因爲它通常是一個永久性的失敗(如列入黑名單的電子郵件地址)。

0

根據您使用的傳輸方式,可能出現更多錯誤。如果你是通過AWS-SES寶石使用Amazon SES服務,添加下面的錯誤給陣列

AWS::SES::ResponseError 

你可以使用一些代碼,這樣搭上了錯誤

# some_utility_class.rb 
# Return false if no error, otherwise returns the error 
    def try_delivering_email(options = {}, &block) 
    begin 
     yield 
     return false 
    rescue EOFError, 
      IOError, 
      TimeoutError, 
      Errno::ECONNRESET, 
      Errno::ECONNABORTED, 
      Errno::EPIPE, 
      Errno::ETIMEDOUT, 
      Net::SMTPAuthenticationError, 
      Net::SMTPServerBusy, 
      Net::SMTPSyntaxError, 
      Net::SMTPUnknownError, 
      AWS::SES::ResponseError, 
      OpenSSL::SSL::SSLError => e 
     log_exception(e, options) 
     return e 
    end 
    end 

# app/controller/your_controller.rb 

if @foo.save 
    send_email 
    ... 


private 

    def send_email 
    if error = Utility.try_delivering_email { MyMailer.my_action.deliver_now } 
     flash('Could not send email : ' + error.message) 
    end 
    end