title: ruby 1.8.7 multithread mail 'uninitialized constant (NameError)'
body: <p>My script sends emails for list of users. I need multithreading because error in 1 address crashes all app. This is my implementation:</p>
  
  <pre><code>  require 'thread'
    &lt;...&gt;
    lock = Mutex.new
    lock.synchronize {
      @model.certs.each{ |user|
        @threads &lt;&lt; Thread.new(user) { |data|
        to = "#{data['name']} #{data['surname']} &lt;#{data['email']}&gt;"
        subject = '&lt;Subject&gt;'
        body = "&lt;Body&gt;"
        view = View.new()
        view.to = to
        view.body = body
        view.subject = subject
        view.attachment = ''
        view.sendMessage()
        @model.sended(data['email'])
        }
      }
    }
  
    @threads.each { |t|
      begin
        t.join
      rescue =&gt; err
        $log.fatal(err)
      end
    }
  </code></pre>
  
  <p><code>view.sendMessage</code> consists:</p>
  
  <pre><code>require 'mail'
  require 'net/smtp'
  &lt;...&gt;
  smtp = Net::SMTP.start(@mailserver)
  mail = Mail.new()
  mail.from = @from
  mail.to = @to
  mail.subject = @subject
  mail.body = @body
  if !@attachment.empty?
    mail.add_file @attachment
  end
  mail.delivery_method :smtp_connection, {
    :connection =&gt; smtp
  }
  mail.deliver
  </code></pre>
  
  <p>And <strong>sometimes</strong> it gives such mistakes as:</p>
  
  <pre><code>uninitialized constant Mail::Field::FromField (NameError)
  /var/lib/gems/1.8/gems/mail-2.4.4/lib/mail/field.rb:189:in `new_field'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>uninitialized constant Mail::CommonAddress::AddressList (NameError)
  /var/lib/gems/1.8/gems/mail-2.4.4/lib/mail/fields/common/common_address.rb:9:in `parse'
  </code></pre>
  
  <p>I have no idea, how it can be fixed. Mutex adding has no result.</p>