views:

57

answers:

1

I am sending emails with the following method:

class Communicate < ActionMailer::Base
  def message(sub,msg,people)
    subject    sub
    bcc        people
    from       '[email protected]'
    sent_on    Time.now

    body       :greeting => msg
  end
end

bcc contains 4 or 5 email addresses.

During my testing I've noticed two things:

  • That if even one of the emails is not an actual email (for example fake_email_no_domain) it does not send emails to any of the recipients
  • if the bcc list has a bad email address (for example [email protected]) then it still sends emails to other recipients but still throws an error to the logs.

In both scenarios the error that is thrown is:

Redirected to http://localhost:3000/
Completed in 2601ms (DB: 1) | 302 Found [http://localhost/notifications]

    [2010-08-04 00:49:00] ERROR Errno::ECONNRESET: Connection reset by peer
        /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
        /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
        /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Questions:

  • Is there any way I can catch this error? I am showing a flash[:notice] to the user and i'd like to mention that something bad happened
  • If my BCC list has 5 emails and really only 4 emails are sent because 5th was nonexistent email then after all is done can I get a number of how many emails were actually sent? I'd like to show that number in my flash[:notice]. I can get this number by actually calling the delivery method in a iteration rather then sending as bulk but still I would not want to increment the count if one email is not sent.
+1  A: 

Add or uncomment following line in the config/environments/development.rb and restart your server.

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

I assume you check for the development for production add line in config/environments/production.rb

Salil
I had that line in development.rb but removing that has no effect. Still that same error is thrown.
Patrick
sorry it's my mistake `Add or uncomment` that line don't remove also don't forget to restart your server.
Salil
I've added it `config.action_mailer.raise_delivery_errors = false` but now it does not even throw errors to the log that it was throwing before...
Patrick