      If auth_user and auth_password are set, they're used to log in.
      If auth_user is None, the EMAIL_HOST_USER setting is used.
      If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
      """
      if auth_user is None:
          auth_user = settings.EMAIL_HOST_USER
      if auth_password is None:
          auth_password = settings.EMAIL_HOST_PASSWORD
      try:
          server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
          if auth_user and auth_password:
              server.login(auth_user, auth_password)
      except:
          if fail_silently:
              return
          raise
      num_sent = 0
      for subject, message, from_email, recipient_list in datatuple:
          if not recipient_list:
              continue
          from_email = from_email or settings.DEFAULT_FROM_EMAIL
          msg = SafeMIMEText(message, 'plain', settings.DEFAULT_CHARSET)
          msg['Subject'] = subject
          msg['From'] = from_email
          msg['To'] = ', '.join(recipient_list)
          msg['Date'] = formatdate()
          try:
              random_bits = str(random.getrandbits(64))
          except AttributeError: # Python 2.3 doesn't have random.getrandbits().
              random_bits = ''.join([random.choice('1234567890') for i in range(19)])
          msg['Message-ID'] = "<%d.%s@%s>" % (time.time(), random_bits, DNS_NAME)
          try:
              server.sendmail(from_email, recipient_list, msg.as_string())
              num_sent += 1
          except:
              if not fail_silently:
                  raise
      try:
          server.quit()
      except:
          if fail_silently:
              return
          raise
      return num_sent
  
  def mail_admins(subject, message, fail_silently=False):
      "Sends a message to the admins, as defined by the ADMINS setting."
      send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], fail_silently)
  
 
</s> remove     send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], fail_silently)
 </s> add     EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
            settings.SERVER_EMAIL, [a[1] for a in
                settings.ADMINS]).send(fail_silently=fail_silently) </s> remove     send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], fail_silently)
 </s> add     EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
            settings.SERVER_EMAIL, [a[1] for a in
                settings.MANAGERS]).send(fail_silently=fail_silently)
 </s> remove     return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently, auth_user, auth_password)
 </s> add     connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    return EmailMessage(subject, message, from_email, recipient_list, connection=connection).send()
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
      If auth_user and auth_password are set, they're used to log in.
      If auth_user is None, the EMAIL_HOST_USER setting is used.
      If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
      """
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
    connection = SMTPConnection(username=auth_user, password=auth_password,
                                 fail_silently=fail_silently)
    messages = [EmailMessage(subject, message, sender, recipient) for subject, message, sender, recipient in datatuple]
    return connection.send_messages(messages)
  
  def mail_admins(subject, message, fail_silently=False):
      "Sends a message to the admins, as defined by the ADMINS setting."
      send_mail(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], fail_silently)
  
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Fixed #3366 -- Part 1 of the email code refactoring and feature extension. This
part refactors email sending into a more object-oriented interface in order to
make adding new features possible without making the API unusable. Thanks to
Gary Wilson for doing the design thinking and initial coding on this.

Includes documentation addition, but it probably needs a rewrite/edit, since
I'm not very happy with it at the moment.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5141 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
django/core/mail.py