code: def loop(self):
          
          for mail in Mail.objects.filter(done=False, send_fail_count__lt=3):
              # send all emails that are not already send or failed to send less
              # then three times
              mail.send_mail()
  
          for mail in Mail.objects.filter(done=True, timestamp__lt=time() - 60 * 60 * 24 * 7):
              # delete all done emails older then one week
              mail.delete()
          return 1, None
docs: check for mails and send them