code: def clear_sent_messages(self, offset=None):
          
          if offset is None:
              offset = getattr(settings, 'MAILQUEUE_CLEAR_OFFSET', defaults.MAILQUEUE_CLEAR_OFFSET)
  
          if type(offset) is int:
              offset = datetime.timedelta(hours=offset)
  
          delete_before = timezone.now() - offset
          self.filter(sent=True, last_attempt__lte=delete_before).delete()
docs: Deletes sent MailerMessage records